LNMP 在docker中

参考的镜像地址

迁移php的项目记得把数据库一起迁走。

https://dockerfile.readthedocs.io/en/latest/content/DockerImages/dockerfiles/php-nginx.html

创建配置目录

mkdir -p /opt/docker/etc/nginx/conf.d
mkdir -p /opt/docker/etc/php/
touch /opt/docker/etc/php/php.ini
mkdir -p /www/web/
chown -R 1000:1000  /www/web/

编辑配置文件

[root@web-protal conf.d]# pwd
/opt/docker/etc/nginx/conf.d
[root@web-protal conf.d]# cat php.conf 
upstream php{
        server 127.0.0.1:9000;
}

vi /opt/docker/etc/nginx/conf.d/www.ggkk.com.conf
    server {
        listen 80;
        server_name   qq.com www.qq.com ;
        root    /app/qq.com;
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
        add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";

        index   index.htm index.html index.php;
        location / {
                try_files $uri $uri/ /index.php?$query_string;
                if (!-e $request_filename) {
                        rewrite ^/index.php(.*)$ /index.php?s=$1 last;
                        rewrite ^/admin.php(.*)$ /admin.php?s=$1 last;
                        rewrite ^/api.php(.*)$ /api.php?s=$1 last;
                        rewrite ^(.*)$ /index.php?s=$1 last;
                        break;
                }
        }


        location ~ \.php$ {
                fastcgi_pass php;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME     $request_filename;
                fastcgi_read_timeout 600;
        }
}

启动容器

docker pull webdevops/php-nginx:7.3-alpine
docker run -d -p 888:80 -p 4443:443--name guakao --restart always \
-v /opt/docker/etc/nginx/conf.d:/opt/docker/etc/nginx/conf.d \
-v /opt/docker/etc/php/php.ini:/opt/docker/etc/php/php.ini \
-v /www/web:/app \
-v /opt/docker/etc/nginx/ssl:/opt/docker/etc/nginx/ssl \
-e php.memory_limit=256M -e PHP_DISMOD=ioncube,redis,opcache,mongodb,pgsql,ldap,memcached -e PHP_DATE_TIMEZONE=PRC \
-e TZ=Asia/Shanghai \
webdevops/php-nginx:7.3-alpine
posted @ 2022-11-06 19:23  Gshelldon  阅读(47)  评论(0编辑  收藏  举报