Nginx官方今天发布了最新的1.3.13开发版本,添加了对于WebSocket协议的支持。 用法当然很简单,基于反向代理,但是入门很容易,用精了难。使用的难点是超时、异常处理、性能优化。如下
其中,初级使用,一定要配置超时时间。否则如同垃圾。没法应用于生产。
参考文章:
nginx官方文章
http://nginx.com/news/nginx-websockets.html
中文nginx支持文章
http://www.iteye.com/news/27188
配置参考文章
http://www.oschina.net/translate/websocket-nginx
location /test {
proxy_pass http://192.168.1.1/;
#链接超时时间,就是nginx读取后端服务器数据的时间,对websocket也有效,空闲超时时间
proxy_read_timeout 1800;
#以下三行,是开启对websocket的支持
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
其中,初级使用,一定要配置超时时间。否则如同垃圾。没法应用于生产。
参考文章:
nginx官方文章
http://nginx.com/news/nginx-websockets.html
中文nginx支持文章
http://www.iteye.com/news/27188
配置参考文章
http://www.oschina.net/translate/websocket-nginx