配置 nginx 以支持 websocket
如果 websocket 中间有反向代理服务器,是不能直接通信的,需要进行配置,以下配置均在 nginx.conf 文件中进行。
首先在 http 节点下新增:
http {
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
}
然后在相应的 server 节点下新增:
http {
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 8020;
server_name localhost;
location / {
proxy_pass http://localhost:8010;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
}
}
}
大概是这样,然后就可以了~
输了你,赢了世界又如何...