docker下php-fpm nginx 环境搭建记录

镜像文件

  1.  bitnami/php-fpm
  2. nginx

continer创建命令

docker run -p 80:80 -v $PWD/host-nginx/www/:/usr/share/nginx/html -v $PWD/host-nginx/config/default.conf:/etc/nginx/conf.d/default.conf --name mynginx nginx

docker run -d -v $PWD/host-nginx/www/:/usr/share/nginx/html --name php-fpm docker.io/bitnami/php-fpm

其中  $PWD为host终端当前目录 

-p  为container内端口与host主机端口映射

-v  为container内文件与host主机文件映射

docroot文件

/usr/share/nginx/html

nginx  confi文件   

/etc/nginx/conf.d/default.log

映射在host主机$PWD/host-nginx/www/目录下

常用基础命令

  • 启停容器                            docker  start/stop   containerID
  • 进入正在运行的容器内      docker attach containerID
  • 进入正在运行的容器目录  docker exec -it containerID /bin/bash
  • 查看容器详细参数             docker inspect  containerID  (可查看container内部IP以及port信息)
  • 显示规格化                        docker inspect --format              
  • 示例   docker inspect --format='{{.Name}} -{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)

 

完成docker下php配置

docker exec 进入目录下

使用pecl完成安装redis,yaml扩展(基本是linux环境,没说明好说的)

mac下安装会有一系列问题,另有mac 下 使用pecl安装php扩展

 

完成nginx配置,主要为default.conf文件修改,

整体server部分如下:

第一版本

默认路由为按url寻找文件

server {
    listen       80;
    server_name  172.17.0.2;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

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

    #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   /usr/share/nginx/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           /usr/share/nginx/html;
       index          index.php;
       fastcgi_pass   172.17.0.2:9000;
       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html/public/$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;
    #}
}

第二版本

单一入口,都从index.php内进入

加入

 location / {
            try_files $uri $uri/ /index.php?$query_string;
        }

nginx不报错浏览器显示空白

docker 内nginx没有fastcgi.conf文件

只能include fastcgi_params

  /etc/nginx/fastcgi_params文件加入代码如下

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_param PATH_INFO $fastcgi_script_name;

 刷线链接出现下载文件问题

忘了原因 挺好修改的

最终可用版本如下:

 

# gzip  on;
    #gzip_min_length 1k;
    # gzip_types text/plain application/javascript text/css application/xml;

    # fastcgi_buffers 32 8k;
    # client_body_buffer_size 1024k;

    # client_max_body_size 1024m;

    # keepalive_timeout  300s;
    # fastcgi_connect_timeout 300s;
    # fastcgi_send_timeout 300s;
    # fastcgi_read_timeout 300s;


    server {
        listen       80;
        server_name  127.0.0.1;
        root         /usr/share/nginx/html/cs_gateway/public/;
        index        index.html index.php;

        #charset koi8-r;

        #access_log  /opt/logs/nginx/access.log  main;
        location = /php_fpm_status {
            include fastcgi_params;
            fastcgi_pass 172.17.0.2:9000;
            fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
        }

        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }

        #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   /usr/share/nginx/html;
        }

	location ~ [^/]\.php(/|$) {
            #root           html;
            fastcgi_pass   172.17.0.2:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO                $fastcgi_script_name;
        }
        
    }

    server {
        listen       8090;
        server_name  127.0.0.1;
        root         /usr/share/nginx/html/lumen/public/;
        index        index.html index.php;

        #charset koi8-r;

        #access_log  /opt/logs/nginx/access.log  main;
        location = /php_fpm_status {
            include fastcgi_params;
            fastcgi_pass 172.17.0.2:9000;
            fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
        }

        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }

        #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   /usr/share/nginx/html;
        }

	location ~ [^/]\.php(/|$) {
            #root           html;
            fastcgi_pass   172.17.0.2:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }
        
    }

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值