Docker 安装 PHP+Nginx

安装Nginx

docker pull nginx

安装PHP

docker pull php:7.3.5-fpm

 

启动PHP-FPM

docker run --name myphpfpm -v /data/ftp:/www -d php:7.3.5-fpm

 /data/ftp 是外部路径  www 是docker里的映射路径

 

Nginx配置文件

server {
    listen       80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm index.php;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ \.php$ {
        fastcgi_pass   php:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /www/$fastcgi_script_name;
        include        fastcgi_params;
    }
}

配置文件说明:

  • php:9000: 表示 php-fpm 服务的 URL,下面我们会具体说明。
  • /www/: 是 myphpfpm 中 php 文件的存储路径,映射到本地的 ~/nginx/www 目录。

 

启动Nginx

docker run --name php_nginx -p 8089:80 -d -v /data/ftp:/user/share/nginx/html:ro -v /data/nginx/conf/conf.d:/etc/nginx/conf.d:ro --link myphpfpm:php nginx

 

  • -p 8089:80: 端口映射,把 nginx 中的 80 映射到本地的 8089 端口。
  • /data/ftp: 是本地 html 文件的存储目录,/usr/share/nginx/html 是容器内 html 文件的存储目录。
  • /data/conf/conf.d: 是本地 nginx 配置文件的存储目录,/etc/nginx/conf.d 是容器内 nginx 配置文件的存储目录。
  • --link myphpfpm:php: 把 myphpfpm 的网络并入 nginx,并通过修改 nginx 的 /etc/hosts,把域名 php 映射成 127.0.0.1,让 nginx 通过 php:9000 访问 php-fpm。
  • ro 表示只读

 

posted @ 2019-05-31 18:10  jso0  阅读(2362)  评论(0编辑  收藏  举报