1、拉取nginx镜像,以及php-fpm镜像
docker pull nginx:1.16.0 docker pull php:5.6.40-fpm2、分别创建nginx 容器php-fpm 容器
# 这里最后吧 /etc/nginx/conf.d 目录和存放静态资源文件的目录挂载到宿主机上来 docker run -d --name nginx_1_16_0 --link php_fpm_5_6_40:php_fpm_5_6_40 nginx:1.16.0 # 这里可以把 存储代码的目录也挂载到宿主机上 docker run -d --name php_fpm_5_6_40 php:5.6.40-fpm3、参考下例编写 nginx 配置文件
server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /var/www/html; index index.html index.htm index.php; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { #proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root /var/www/html; # php-fpm 容器代码存放路径 fastcgi_pass php_fpm_5_6_40:9000; # php_fpm_5_6_40 是启动nginx时候link参数第二个值 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache‘s document root # concurs with nginx‘s one # location ~ /\.ht { deny all; } }4、重启nginx容器
docker restart <容器ID>参考链接:
https://blog.csdn.net/qq_35765928/article/details/87715448
https://blog.csdn.net/qq_38711879/article/details/105407750
基于Docker搭建 Php-fpm + Nginx 环境
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)