配置nginx,注意加粗就是需要加的server配置信息:
客户端发起协议升级的请求,而nginx在拦截时需要识别出这是一个协议升级(upgrade)的请求,所以必须显式设置升级(Upgrade head)和连接头(Connection head)。
server { listen 7669; server_name onlineVisitHttpServer; location / { proxy_http_version 1.1; proxy_pass_header Server; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass http://127.0.0.1:7701; proxy_set_header Connection $connection_upgrade; proxy_set_header Upgrade $http_upgrade; } } 配置完这些还要配置http配置:
map 代码段该作用主要是根据客户端请求中 $http_upgrade 的值,来构造改变 $connection_upgrade 的值,即根据变量 $http_upgrade 的值创建新的变量 $connection_upgrade。
http { include mime.types; default_type application/octet-stream; map $http_upgrade $connection_upgrade {//把这些加进去 default upgrade; ‘’ close; } #access_log logs/access.log main; sendfile on; #tcp_nopush on;
|