worker_processes auto; pid /tmp/nginx.pid; # 非特权用户可写 events { worker_connections 1024; } http { # 设置非特权用户可写的临时路径 client_body_temp_path /tmp/client_body; proxy_temp_path /tmp/proxy_temp; fastcgi_temp_path /tmp/fastcgi_temp; include /etc/nginx/mime.types; # 定义 WebSocket 升级映射(更优雅的写法) map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { listen 7860; server_name localhost; # 根目录反代 8080 (C/C++ 服务) location /chat { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } # /bot 路径反代 8888 (Python 服务) location /bot { proxy_pass http://127.0.0.1:8888; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } location / { proxy_pass http://0.0.0.0:2017; # 你的 v2rayA 地址 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; } location /ttyd/ { proxy_pass http://127.0.0.1:7681/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; # 核心:解决 WebSocket 断连问题 proxy_read_timeout 86400s; # 增加读取超时时间 proxy_send_timeout 86400s; # 增加发送超时时间 # 如果你的面板有特定限制,可能需要缓存设置 proxy_buffering off; # WebSocket 建议关闭缓冲 } } }