chore(docker): 增加支持websocket转发功能,PHP容器不暴漏端口到主机

This commit is contained in:
2025-12-19 15:32:34 +08:00
parent 498122f57e
commit ba5c2239ac
10 changed files with 35 additions and 20 deletions

2
.env
View File

@@ -7,8 +7,6 @@ APP_ENV=development
# PHP/PHP-FPM 配置 # PHP/PHP-FPM 配置
PHP_VERSION=7.4 PHP_VERSION=7.4
PHP_FPM_VERSION=7.4-fpm PHP_FPM_VERSION=7.4-fpm
PHP_FPM_PORT=9100
XDEBUG_POST=9103
# 数据库配置 # 数据库配置
MYSQL_ROOT_HOST=% MYSQL_ROOT_HOST=%

View File

@@ -7,8 +7,6 @@ APP_ENV=development
# PHP/PHP-FPM 配置 # PHP/PHP-FPM 配置
PHP_VERSION=7.4 PHP_VERSION=7.4
PHP_FPM_VERSION=7.4-fpm PHP_FPM_VERSION=7.4-fpm
PHP_FPM_PORT=9105
XDEBUG_POST=9108
# 数据库配置 # 数据库配置
MYSQL_ROOT_HOST=% MYSQL_ROOT_HOST=%

View File

@@ -7,8 +7,6 @@ APP_ENV=development
# PHP/PHP-FPM 配置 # PHP/PHP-FPM 配置
PHP_VERSION=7.4 PHP_VERSION=7.4
PHP_FPM_VERSION=7.4-fpm PHP_FPM_VERSION=7.4-fpm
PHP_FPM_PORT=9100
XDEBUG_POST=9103
# 数据库配置 # 数据库配置
MYSQL_ROOT_HOST=% MYSQL_ROOT_HOST=%

View File

@@ -7,8 +7,6 @@ APP_ENV=local
# PHP/PHP-FPM 配置 # PHP/PHP-FPM 配置
PHP_VERSION=7.4 PHP_VERSION=7.4
PHP_FPM_VERSION=7.4-fpm PHP_FPM_VERSION=7.4-fpm
PHP_FPM_PORT=9100
XDEBUG_POST=9103
# 数据库配置 # 数据库配置
MYSQL_ROOT_HOST=% MYSQL_ROOT_HOST=%

View File

@@ -27,8 +27,6 @@ services:
# 不然ThinkPHP 6.x 系列,会只加载 .env 文件,而不会加载 .env.local 文件,导致 .env.local 文件中的配置不会生效 # 不然ThinkPHP 6.x 系列,会只加载 .env 文件,而不会加载 .env.local 文件,导致 .env.local 文件中的配置不会生效
APP_ENV: ${APP_ENV:-local} APP_ENV: ${APP_ENV:-local}
APP_DEBUG: ${APP_DEBUG:-true} APP_DEBUG: ${APP_DEBUG:-true}
ports:
- "${PHP_FPM_PORT:-9000}:9000" # PHP-FPM
volumes: volumes:
- ./:/var/www/all_source - ./:/var/www/all_source
- ./src:/var/www/html - ./src:/var/www/html

View File

@@ -25,8 +25,6 @@ services:
# 不然ThinkPHP 6.x 系列,会只加载 .env 文件,而不会加载 .env.local 文件,导致 .env.local 文件中的配置不会生效 # 不然ThinkPHP 6.x 系列,会只加载 .env 文件,而不会加载 .env.local 文件,导致 .env.local 文件中的配置不会生效
APP_ENV: ${APP_ENV:-development} APP_ENV: ${APP_ENV:-development}
APP_DEBUG: ${APP_DEBUG:-true} APP_DEBUG: ${APP_DEBUG:-true}
ports:
- "${PHP_FPM_PORT:-9000}:9000" # PHP-FPM
volumes: volumes:
- ./:/var/www/all_source - ./:/var/www/all_source
- ./src:/var/www/html - ./src:/var/www/html

View File

@@ -0,0 +1,7 @@
location /ws {
proxy_pass http://php-fpm:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}

View File

@@ -24,6 +24,9 @@
include conf.c/enable-php-74.conf; include conf.c/enable-php-74.conf;
#PHP-INFO-END #PHP-INFO-END
# 启用 WebSocket 支持
include conf.c/enable-websocket.conf;
# --- REWRITE-START --- URL重写规则引用,修改后将导致面板设置的伪静态规则失效 # --- REWRITE-START --- URL重写规则引用,修改后将导致面板设置的伪静态规则失效
# include /www/server/panel/vhost/rewrite/xcx30.5g-quickapp.com.conf; # 等于下面的内容 # include /www/server/panel/vhost/rewrite/xcx30.5g-quickapp.com.conf; # 等于下面的内容
location / { location / {

View File

@@ -54,15 +54,15 @@ RUN composer --version
# 修改 PHP 配置 # 修改 PHP 配置
RUN echo "memory_limit=256M" > /usr/local/etc/php/conf.d/memory-limit.ini \ RUN echo "memory_limit=256M" > /usr/local/etc/php/conf.d/memory-limit.ini \
&& echo "upload_max_filesize=50M" >> /usr/local/etc/php/conf.d/uploads.ini \ && echo "upload_max_filesize=150M" >> /usr/local/etc/php/conf.d/uploads.ini \
&& echo "post_max_size=50M" >> /usr/local/etc/php/conf.d/uploads.ini && echo "post_max_size=150M" >> /usr/local/etc/php/conf.d/uploads.ini
# # 使用Composer安装项目依赖可选根据需要启用, 更多的时候,会出错,要在容器中执行操作) # # 使用Composer安装项目依赖可选根据需要启用, 更多的时候,会出错,要在容器中执行操作)
# RUN composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ # RUN composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
# RUN composer install --no-dev --optimize-autoloader --working-dir=/var/www/html # RUN composer install --no-dev --optimize-autoloader --working-dir=/var/www/html
# 暴露端口 # 暴露端口9000 为 PHP-FPM 端口8080 为 WebSocket 端口
EXPOSE 9000 EXPOSE 9000 8080
############ 查看 cron 进程 ############ 查看 cron 进程
## 查看 cron 进程 ## 查看 cron 进程

View File

@@ -6,12 +6,14 @@ logfile_backups=10
loglevel=info loglevel=info
pidfile=/var/run/supervisord.pid pidfile=/var/run/supervisord.pid
[program:chmod] [program:php-permission-change]
command=/bin/bash -c "while true; do chmod -R 775 /var/www/html/runtime/ /var/www/html/upload/ 2>/dev/null || true; sleep 30; done" command=/bin/bash -c "sleep 15 && /usr/local/bin/entrypoint.sh"
autostart=true autostart=true
autorestart=true autorestart=true
stopasgroup=true stopasgroup=true
killasgroup=true killasgroup=true
stdout_logfile=/var/log/supervisor/php-permission-change.log
stderr_logfile=/var/log/supervisor/php-permission-change-error.log
[program:php-fpm] [program:php-fpm]
command=php-fpm command=php-fpm
@@ -42,4 +44,19 @@ stderr_logfile=/var/log/supervisor/think-cron-error.log
stderr_logfile_maxbytes=10MB stderr_logfile_maxbytes=10MB
stderr_logfile_backups=10 stderr_logfile_backups=10
startsecs=3 startsecs=3
stopwaitsecs=10 stopwaitsecs=10
[program:websocket-server]
command=php src/ws_server.php
workdir=/var/www/html
autostart=true
autorestart=true
startretries=3
stdout_logfile=/var/log/supervisor/websocket-server.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=10
stderr_logfile=/var/log/supervisor/websocket-server-error.log
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=10
startsecs=3
stopwaitsecs=10