docker-compose 搭建php+nginx+mysql+redis

参考:https://gitee.com/Tinywan/dnmp

拉取代码

 git clone https://gitee.com/Tinywan/dnmp.git
 cd dnmp 

新建配置文件

cp env.example .env

 

修改.env,对应共享目录

SOURCE_SHARE_DIR=/mnt/hgfs/www

  

开启容器服务

docker-compose up
#docker-compose -f /mnt/hgfs/www/dnmp/docker-compose.yml up

守护进程 docker-compose up -d

nginx配置

配置文件端口必须和 docker-compose.ymlports - 8088:80中的映射出来的端口一一对应

修改dnmp\conf\nginx.conf 

#dnmp\conf\nginx.conf 
upstream fastcgi_proxy{
        server php74:9000;
    }

  

#dnmp\conf\conf.d\hlyun\hlyun_gateway.conf
server {
        listen       7003;
        server_name  localhost;
        location / {
            root   /var/www/113frontend/dist;
            index  index.html index.htm index.php;
            if (!-e $request_filename) {
                rewrite ^/(.*)$ / redirect;
            }
        }

        error_page   500 502 503 504  /50x.html;
       
        location /api {
        #rewrite ^.+api/?(.*)$ /$1 break;
        #include uwsgi_params;
        proxy_pass http://localhost:7002;
        }

    }

server {
        listen       7002;
        server_name  localhost;
        location / {
            root   /var/www/hlyun_v3/hlyun_gateway/src/public;
            index  index.html index.htm index.php;
            try_files $uri $uri/ /index.php?$query_string;
        }
        error_page   500 502 503 504  /50x.html;
        location ~ \.php$ {
            root           /var/www/hlyun_v3/hlyun_gateway/src/public;
            fastcgi_pass   fastcgi_proxy;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

    }
   

   

  

重新加载配置文件 docker exec -it dnmp-nginx nginx -s reload

修改php-fpm:

#dnmp\conf\php\php-fpm.d\www.conf
pm = static
pm.max_children = 30

进入PHP容器(该容器没有bash shell。但在/bin/sh有一个shell):

docker exec -it dnmp-php74 /bin/sh

  

mysql5.7导入DATETIME字段数据时遇到错误incorrect datetime value '0000-0-0 00:00:00' for column

解决办法:去掉NO_ZERO_IN_DATE,NO_ZERO_DATE

#dnmp\conf\mysql\my.cnf
sql_mode ='STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

  

posted @ 2021-03-15 15:53  佚小名  阅读(754)  评论(0编辑  收藏  举报