https://github.com/zhuima/nginx-ws
nginx proxy websocket
https://github.com/zhuima/nginx-ws
Last synced: 11 months ago
JSON representation
nginx proxy websocket
- Host: GitHub
- URL: https://github.com/zhuima/nginx-ws
- Owner: zhuima
- Created: 2018-12-01T03:58:12.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-20T01:49:26.000Z (about 7 years ago)
- Last Synced: 2025-05-31T06:17:22.875Z (about 1 year ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
nginx-ws-demo
=============
[TOC]
### 一、nginx负载均衡websocket注意事项
- 和普通代理不一样的地方
```python
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
```
### 二、参考文档
[配置 Nginx 反向代理 WebSocket](https://www.hi-linux.com/posts/42176.html)
[神策服务转发配置](https://www.sensorsdata.cn/manual/data_import_nginx.html)
### 三、使用方式
```python
npm --registry=https://registry.npm.taobao.org install ws
cd ws
node server.js
# 如果想实现负载,复制ws目录,然后修改下对应的端口即可
```
### 四、测试
- npm --registry=https://registry.npm.taobao.org install wscat
- cd ~/node_modules/wscat/
- ./bin/wscat --connect ws://yourdomain
- send message test
- 查看服务器端的日志
### 五、关于ip_hash
- 有些文档表示一定要使用ip_hash,确保数据的有序,但是没有验证
- 另外就是ip_hash就是统一客户端的请求始终会落到后端的其中一个节点上,所以要特别注意