1)原理
2)nginx配置
http {
include mime.types;
default_type application/octet-stream;
# 如果 $http_upgrade 不为 '' (空),则 $connection_upgrade 为 upgrade 。
# 如果 $http_upgrade 为 '' (空),则 $connection_upgrade 为 close。
map $http_upgrade $connection_upgrade{
default upgrade;
'' close;
}
upstream webservers{
server 127.0.0.1:8080 weight=90 ;
}
server {
listen 80;
server_name localhost;
# WebSocket
location /ws/ {
proxy_pass http://webservers/ws/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "$connection_upgrade";
}
}
}