docker 部署PHP+ nginx环境

作者: print("") 分类: linux 发布时间: 2018-08-03 20:05

首先push 两个镜像

docker pull php:7.2.3-fpm
docker pull nginx

然后启动一个php 

docker run --name phpfpm -d -v /root/app:/app php:7.2.3-fpm

说明一下 –name 是容器的名字 phpfpm

-v 是/root/app 是本机的地址

/app 是容器内部的存储位置

然后再启动一个nginx 

docker run --name nginx_server -d -p 80:80 --link phpfpm:phpfpm -v /root/conf/nginx.conf:/etc/nginx/nginx.conf --volumes-from phpfpm  nginx

— link phpfrpm:phpfpm    是容器之间建立关系

–volumes-from  phpfpm   就是把/root/app:/app 也会导入到 容器中/app 目录 

-v  /root/conf/nginx.conf   导入到 /etc/nginx/nginx.conf    宿主机 的nginx.conf 的导入到/etc/nginx/nginx.conf  中 

连接PHP的配置如下:

        location ~ .php$ {
        root          /app;
        fastcgi_pass   phpfpm:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME /app$fastcgi_script_name;
        include        fastcgi_params;
        }

nginx配置文件如下:

user  root root;
worker_processes auto;
error_log  /tmp/nginx_error.log  crit;
pid        /tmp/nginx.pid;
worker_rlimit_nofile 51200;

events
    {
        use epoll;
        worker_connections 51200;
        multi_accept on;
    }

http
    {
        include       mime.types;
        default_type  application/octet-stream;
        server_names_hash_bucket_size 512;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;

        sendfile   on;
        tcp_nopush on;

        keepalive_timeout 60;

        tcp_nodelay on;

        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;
		fastcgi_intercept_errors on;


server
    {
        listen 80;
        server_name www.bt.cn;
        index index.html index.htm index.php;
        root  /app;

        #error_page   404   /404.html;
        location ~ .php$ {
        root          /app;
        fastcgi_pass   phpfpm:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME /app$fastcgi_script_name;
        include        fastcgi_params;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /tmp/access.log;
    }
}

访问80端口如下:

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

说点什么

avatar
  Subscribe  
提醒