feat: fix WebSocket connection timeout 600s,overwrite 60s timeout

This commit is contained in:
shenjianZ 2025-07-30 16:23:10 +08:00
parent 5e89bff405
commit 1f01ff97ad
2 changed files with 56 additions and 17 deletions

View File

@ -32,7 +32,7 @@ services:
container_name: email-nginx container_name: email-nginx
restart: always restart: always
ports: ports:
- "7614:80" # HTTP - "80:80" # HTTP
- "443:443" # HTTPS (需要SSL证书) - "443:443" # HTTPS (需要SSL证书)
- "25:25" # SMTP 端口,转发给后端 - "25:25" # SMTP 端口,转发给后端
volumes: volumes:
@ -40,8 +40,8 @@ services:
- ./frontend/dist:/usr/share/nginx/html - ./frontend/dist:/usr/share/nginx/html
# 挂载 Nginx 配置文件 # 挂载 Nginx 配置文件
- ./nginx.full.conf:/etc/nginx/nginx.conf:ro - ./nginx.full.conf:/etc/nginx/nginx.conf:ro
# (可选) 挂载 SSL 证书 # 挂载 SSL 证书
# - ./certs:/etc/nginx/certs:ro - ./certs:/etc/nginx/certs:ro
depends_on: depends_on:
- backend - backend
- mysql - mysql

View File

@ -1,30 +1,69 @@
events {} worker_processes 1;
events {
worker_connections 1024;
}
http { http {
server { charset utf-8;
listen 7614; include mime.types;
default_type application/octet-stream;
# 启用 SSL 协议,建议加上 TLSv1.3
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
sendfile on;
keepalive_timeout 65;
# HTTP 80 端口,重定向到 HTTPS
server {
listen 80;
server_name mail.shenjianl.cn; # 改为你自己的域名
# 统一重定向到 HTTPS
return 301 https://$host$request_uri;
}
# HTTPS 443 端口主服务
server {
listen 443 ssl;
server_name mail.shenjianl.cn; # 改为你自己的域名
ssl_certificate /etc/nginx/certs/mail.shenjianl.cn_bundle.pem; # 改为你自己的证书文件
ssl_certificate_key /etc/nginx/certs/mail.shenjianl.cn.key; # 改为你自己的密钥文件
root /usr/share/nginx/html;
index index.html;
# 前端静态文件
location / { location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html; try_files $uri $uri/ /index.html;
} }
# 后端 API 转发 # 反向代理 /api 到后端服务
location /api { location /api {
proxy_pass http://backend:5182; proxy_pass http://email-backend:5182;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Proto $scheme;
} }
}
}
stream { # WebSocket 支持
server { location /ws {
listen 25; proxy_pass http://email-backend:5182;
proxy_pass backend:25; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
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 600s;
proxy_send_timeout 600s;
}
} }
} }