events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; map $http_upgrade $connection_upgrade { default upgrade; '' close; } # 标记是否为 WebSocket 请求 map $http_upgrade $is_websocket { default 0; websocket 1; } upstream easytier_backend { server 127.0.0.1:7880; keepalive 64; } server { listen 7860; server_name localhost; # 方式1:内部代理位置(推荐) location /_ws { internal; # 只允许内部重写访问 proxy_pass http://easytier_backend; 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; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_buffering off; proxy_read_timeout 3600s; proxy_send_timeout 3600s; } # 主 location location / { # WebSocket 请求内部重写到 /_ws if ($is_websocket) { rewrite ^/(.*)$ /_ws/$1?$args last; } # 普通 HTTP 请求 root /var/www/html; index index.html; try_files $uri $uri/ /index.html; } } }