`
李俊良
  • 浏览: 141656 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

nginx 反向代理nodejs websocket,实现负载均衡

 
阅读更多

 

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对应的独立域名就行,别混合用,混合弄比较容易出问题点

0
3
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics