问题说明
1.nginx代理接口后,websocket接口会连不上
配置示例
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location ^~ /websocket/ {
rewrite ^/websocket/(.*)$ /$1 break;
proxy_set_header Upgrade $http_upgrade;
proxy_http_version 1.1;
# 不设置时间,连上后可能立马就断开了
proxy_read_timeout 60s;
proxy_set_header Connection $connection_upgrade;
proxy_pass http://172.1.1.1:8888;
}
}