1.要求安装nginx1.3以上版本,具体安装请查询各种文档
2.nginx配置
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream nodesocket {
server 127.0.0.1:10080 fail_timeout=20s;
server 127.0.0.1:10081 fail_timeout=20s;
}
server {
listen 80;
server_name socket.localhost.com;
location / {
proxy_pass http://nodesocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
3.基本上这样就行了
需要注意的点
做的测试页面使用另外一个域名,然后去连socket对应的独立域名就行,别混合用,混合弄比较容易出问题点