Nginx 各种代理姿势 发表于 2024-02-28 更新于 2024-10-06 接口代理1234567891011location /apis { proxy_set_header Host $http_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; rewrite ^/apis/(.*)$ /$1 break; proxy_pass http://test.amazonaws.com:8082; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection upgrade;} Websocket 代理123456789101112location /ws/ { proxy_pass http://test.amazonaws.com:8082/ws; proxy_http_version 1.1; proxy_read_timeout 360s; proxy_redirect off; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; #配置连接为升级连接 proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;} Cloudflare Image反向代理123456789101112131415location /image/ { rewrite ^/image/(.*)$ /xxxxx/$1/public break; proxy_pass https://imagedelivery.net; proxy_ssl_name imagedelivery.net; proxy_ssl_server_name on; proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; proxy_set_header Host imagedelivery.net; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection upgrade; proxy_hide_header Upgrade; proxy_hide_header Alt-Svc; proxy_hide_header Expect-CT; proxy_http_version 1.1; proxy_set_header Connection "";} 静态图片1234567891011121314location /static { alias /xx/xxx; proxy_ssl_name imagedelivery.net; proxy_ssl_server_name on; proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; proxy_set_header Host imagedelivery.net; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection upgrade; proxy_hide_header Upgrade; proxy_hide_header Alt-Svc; proxy_hide_header Expect-CT; proxy_http_version 1.1; proxy_set_header Connection "";}