示例
map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { listen 80; server_name xxx.xxx.cn; return 301 https://xxx.xxx.cn$request_uri; } server { listen 443 ssl; server_name xxx.xxx.cn; ssl_certificate /home/ubuntu/certs/xxx.xxx.cn/public.crt; ssl_certificate_key /home/ubuntu/certs/xxx.xxx.cn/private.key; location / { proxy_pass http://127.0.0.1:3000; 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 HTTP_X_FORWARDED_FOR $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_http_version 1.1; #新增 proxy_set_header Upgrade $http_upgrade; #新增 proxy_set_header Connection $connection_upgrade; #新增 proxy_redirect default; } }点击复制复制失败已复制
说明:
区别于普通反向代理的地方在于:
- 增加
map
代码块 location
中标注新增
部分