diff --git a/docker/nginx/conf.c/enable-websocket.conf b/docker/nginx/conf.c/enable-websocket.conf index a8bce07a7..69bc4c6ef 100644 --- a/docker/nginx/conf.c/enable-websocket.conf +++ b/docker/nginx/conf.c/enable-websocket.conf @@ -1,7 +1,14 @@ location /ws { - proxy_pass http://php-fpm:8080; + proxy_pass http://php-fpm:8080; # 注意:这里用的是 Docker 服务名或容器名 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; - proxy_set_header Host $host; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + # 可选:设置超时(WebSocket 是长连接) + proxy_read_timeout 86400s; + proxy_send_timeout 86400s; } \ No newline at end of file diff --git a/docker/nginx/sites-enabled/app.conf b/docker/nginx/sites-enabled/app.conf index 105c7c9ed..c7b433b2f 100644 --- a/docker/nginx/sites-enabled/app.conf +++ b/docker/nginx/sites-enabled/app.conf @@ -20,13 +20,13 @@ # add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; # --- SSL configuration end --- + # 启用 WebSocket 支持 + include conf.c/enable-websocket.conf; + #PHP-INFO-START PHP引用配置,可以注释或修改 include conf.c/enable-php-74.conf; #PHP-INFO-END - # 启用 WebSocket 支持 - include conf.c/enable-websocket.conf; - # --- REWRITE-START --- URL重写规则引用,修改后将导致面板设置的伪静态规则失效 # include /www/server/panel/vhost/rewrite/xcx30.5g-quickapp.com.conf; # 等于下面的内容 location / { diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index eeeb5ea71..ab5bd85da 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -27,9 +27,14 @@ RUN apt-get update && apt-get install -y \ libfreetype6-dev \ libjpeg62-turbo-dev \ libpng-dev \ - iputils-ping \ + iputils-ping \ + && apt-get clean \ && rm -rf /var/lib/apt/lists/* +# 安装 WebSocat 完成后,清理缓存 +COPY ./websocat /usr/local/bin/websocat +RUN chmod +x /usr/local/bin/websocat + # 安装 PHP 扩展 RUN docker-php-ext-configure gd --with-freetype --with-jpeg \ && docker-php-ext-install \ diff --git a/docker/php/supervisord.conf b/docker/php/supervisord.conf index 5a874a711..99fb8ffc5 100644 --- a/docker/php/supervisord.conf +++ b/docker/php/supervisord.conf @@ -47,7 +47,7 @@ startsecs=3 stopwaitsecs=10 [program:websocket-server] -command=php src/ws_server.php +command=php ./ws_server.php workdir=/var/www/html autostart=true autorestart=true diff --git a/docker/php/websocat b/docker/php/websocat new file mode 100644 index 000000000..53696208c Binary files /dev/null and b/docker/php/websocat differ