• PHP7 +nginx Docker 部署


    一、php docker

    1、创建php Docker, Dockerfile文件如下

    1. FROM php:7.3.7-fpm
    2. RUN mkdir -p /php/myphp

     2、启动脚本start.sh,其中会安装php mysql驱动

    1. #!/bin/bash
    2. rm -rf myphp
    3. unzip myphp.zip
    4. cp .env.pro ./myphp
    5. cp .env ./myphp
    6. docker rm -f myphp
    7. docker build -t myphp .
    8. docker run -d --network lt-pro-net --name myphp --privileged=true -p 19000:9000 --restart=always -v /home/docker/myphp/:/php/myphp/ -v /home/docker/myphp/php.ini:/usr/local/etc/php/php.ini myphp:latest
    9. chmod -R 777 /home/docker/myphp/
    10. #docker-php-ext-install pdo pdo_mysql
    11. docker exec -it myphp bash -c "docker-php-ext-install pdo pdo_mysql"
    12. docker restart myphp

    其中.env文件指定pro环境,.env.pro中为配置

    php.ini需要设置mysqlnd 

     

    二、php nginx docker

    1、创建php nginx 的Docker脚本 Dockerfile文件如下

    1. FROM nginx:1.19.0
    2. ENV TZ='Asia/Shanghai'
    3. #one app create one log path
    4. RUN mkdir -p /log/myphp

    2、php nginx配置如下 myphp.conf

    1. server {
    2. listen 9001;
    3. server_name localhost;
    4. root /php/myphp/public;
    5. access_log /log/myphp/access-test.log main;
    6. error_log /log/myphp/error-test.log error;
    7. client_max_body_size 0;
    8. client_header_buffer_size 32k;
    9. large_client_header_buffers 4 16k;
    10. client_header_timeout 1m;
    11. client_body_timeout 120s;
    12. location / {
    13. add_header Access-Control-Allow-Origin * always;
    14. add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS, PUT, DELETE';
    15. add_header Access-Control-Allow-Headers 'token,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
    16. index index.php index.html index.htm;
    17. try_files $uri $uri/ /index.php?$query_string;
    18. }
    19. error_page 500 502 503 504 /50x.html;
    20. location = /50x.html {
    21. root html;
    22. }
    23. location ~ \.php$ {
    24. fastcgi_pass myphp:9000;
    25. fastcgi_index index.php;
    26. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    27. include fastcgi_params;
    28. }
    29. }

    3、执行脚本start.sh

    1. #!/bin/bash
    2. docker rm -f lt-php-nginx
    3. docker build -t lt-php-nginx .
    4. docker run --name lt-php-nginx --privileged=true --restart=always \
    5. --network lt-pro-net \
    6. -v /home/docker/app/php-nginx/conf.d:/etc/nginx/conf.d \
    7. -p 9001:9001\
    8. -v /home/docker/myphp:/php/myphp \
    9. -v /home/docker/myphp/log:/log/myphp \
    10. --link myphp:myphp \
    11. -d nginx

     

  • 相关阅读:
    OpenCV技术应用(3)— 把.png图像保存为.jpg图像
    java 归档版本的下载入口
    Android中获取唯一的id
    Elasticsearch终端命令行用法大全
    基于java+ssm+vue+mysql的社区流浪猫狗救助网站
    什么是IPQC(制程控制)?
    C++ 位拷贝
    1.Linux的目录结构
    使用tailwindcss轻松实现移动端rem适配
    Java回顾-动态代理
  • 原文地址:https://blog.csdn.net/liln0530/article/details/138059709