配置很简单,增加一个Mapping 捕获参数。增加四个Header. 👇
upstream node {
hash $remote_addr consistent;
server 127.0.0.1:8080;
}
+ map $http_upgrade $connection_upgrade {
+ default upgrade;
+ '' close;
+ }
server {
location / {
proxy_pass http://node;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header Upgrade $http_upgrade;
+ proxy_set_header Connection $connection_upgrade;
+ proxy_read_timeout 3600s;
+ proxy_http_version 1.1;
}
server_name haha;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/haha; # managed by Certbot
ssl_certificate_key /etc/haha; # managed by Certbot
include /etc/haha; # managed by Certbot
ssl_dhparam /etc/haha; # managed by Certbot
}
server {
if ($host = haha) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name haha;
listen 80;
return 404; # managed by Certbot
}
配置很简单,增加一个Mapping 捕获参数。增加四个Header. 👇
upstream node {
hash $remote_addr consistent;
server 127.0.0.1:8080;
}
+ map $http_upgrade $connection_upgrade {
+ default upgrade;
+ '' close;
+ }
server {
location / {
proxy_pass http://node;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header Upgrade $http_upgrade;
+ proxy_set_header Connection $connection_upgrade;
+ proxy_read_timeout 3600s;
+ proxy_http_version 1.1;
}
server_name haha;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/haha; # managed by Certbot
ssl_certificate_key /etc/haha; # managed by Certbot
include /etc/haha; # managed by Certbot
ssl_dhparam /etc/haha; # managed by Certbot
}
server {
if ($host = haha) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name haha;
listen 80;
return 404; # managed by Certbot
}