码迷,mamicode.com
首页 > Web开发 > 详细

基于Docker搭建 Php-fpm + Nginx 环境

时间:2021-07-27 17:31:51      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:doc   page   ref   restart   编写   挂载   targe   oca   static   

1、拉取nginx镜像,以及php-fpm镜像

docker pull nginx:1.16.0
docker pull php:5.6.40-fpm

2、分别创建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-fpm

3、参考下例编写 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 环境

标签:doc   page   ref   restart   编写   挂载   targe   oca   static   

原文地址:https://www.cnblogs.com/GetcharZp/p/15062691.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!