nginx websocket
前两天折腾了下socketio,部署完发现通过nginx代理之后前端的socket无法和后端通信了,于是暴查一通,最后解决问题:
location / {
proxy_pass http://127.0.0.1:9999;
proxy_connect_timeout 60;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
# 下面是关键
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# 这是配置webpysessoin丢失的问题
fastcgi_param SCRIPT_NAME "";
}
参考: 1. http://nginx.org/en/docs/http/websocket.html
http://stackoverflow.com/questions/12102110/nginx-to-reverse-proxy-websockets-and-enable-ssl-wss
The basics of the NGINX configuration is reproduced below:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream appserver {
server 192.168.100.10:9222; # appserver_ip:ws_port
}
server {
listen 8888; // client_wss_port
ssl on;
ssl_certificate /path/to/crt;
ssl_certificate_key /path/to/key;
location / {
proxy_pass http://appserver;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
Browsing the source code and a little help from http://stackoverflow.com/questions/12102110/nginx-to-reverse-proxy-websockets-and-enable-ssl-wss#comment16394844_12102112 I was able to get it working with:
tcp {
upstream websockets {
server 127.0.0.1:55674;
check interval=3000 rise=2 fall=5 timeout=1000;
}
server {
listen 80;
server_name stomp.ideedock.local;
timeout 43200000;
websocket_connect_timeout 43200000;
websocket_read_timeout 43200000;
websocket_send_timeout 43200000;
proxy_connect_timeout 43200000;
proxy_read_timeout 43200000;
proxy_send_timeout 43200000;
so_keepalive on;
tcp_nodelay on;
websocket_pass websockets;
websocket_buffer 1k;
}
}
nginx websocket的更多相关文章
- WebSocket :Nginx+WebSocket内部路由策略推送服务器的实现(附可生产环境应用代码)
1.项目背景 前几天写了一篇WebSocket推送的博客:WebSocket :用WebSocket实现推送你必须考虑的几个问题 支持的连接数大概几千个,具体数量依赖于tomcat能并发的线程数,但很 ...
- Nginx websocket反向代理
L:106 现在主流的反向代理,通过长链接可以从服务器推送数据到页面 升级成websocket反向代理必须根据上面的配置做配置 缺点无法多路复用,也就是没办法并行 我们测试下Websocket反向代理 ...
- tomcat 7下spring 4.x mvc集成websocket以及sockjs完全参考指南(含nginx/https支持)
之所以sockjs会存在,说得不好听点,就是因为微软是个流氓,现在使用windows 7的系统仍然有近半,而windows 7默认自带的是ie 8,有些会自动更新到ie 9,但是大部分非IT用户其实都 ...
- Nginx反向代理websocket配置实例(官网)
https://www.nginx.com/blog/websocket-nginx/ Blog Tech Rick Nelson of NGINX, Inc. May 16, 2014 NG ...
- tomcat 7下spring 4.x mvc集成websocket以及sockjs完全参考指南
之所以sockjs会存在,说得不好听点,就是因为微软是个流氓,现在使用windows 7的系统仍然有近半,而windows 7默认自带的是ie 8,有些会自动更新到ie 9,但是大部分非IT用户其实都 ...
- Nginx SPDY Pagespeed模块编译——加速网站载入
在看<Web性能权威指南>的时候,看到了SPDY这货,于是便开始折腾起了这个了,也顺便把pagespeed加了进去. Nginx SPDY 引自百科~~ SPDY(读作“SPeeDY”)是 ...
- 实战http切换成https
Server端使用Nginx + Tomcat Niginx SSL on Tomcat SSL non 步骤: 1.修改代码,将外部引用的http js css 文件修改为https,若外部链接不支 ...
- linuxWeb环境安装——小皮面板不错的面板
安装环境为最新的:CentOS8.1.1911 linux的web环境安装,说白了,弄明白了就不难.为此阅读了多部文献,最先的是linux教程,重理论轻实践:之后,看了鸟哥的私房菜,有2本,每本都8 ...
- spring4+websocket+nginx详细配置
实现的版本jdk1.7.0_25, tomcat7.0.47.0, Tengine/2.1.1 (nginx/1.6.2), servlet3.0, spring4.2.2 使用maven导入版本3. ...
随机推荐
- project修改时间日历
视图→甘特图 格式→时间表→右键时间表 详细的日程表,然后双击时间即可
- Oracle 优化器
http://blog.csdn.net/it_man/article/details/8185370一.优化器基本知识 Oracle在执行一个SQL之前,首先要分析一下语句的执行计划,然后再按执 ...
- Visual Studio 2015官方下载 秘钥破解
微软刚刚为开发人员奉上了最新大礼Visual Studio 2015正式版.如果你是MSDN订阅用户,现在就可以去下载丰富的相关资源.如果你指向体验一把尝尝鲜,微软也是很慷慨的. Visual Stu ...
- [转]如何用C++实现一个LRU Cache
[转自http://hawstein.com/posts/lru-cache-impl.html] LRU是Least Recently Used的缩写,意思是最近最少使用,它是一种Cache替换算法 ...
- Codeforces Hello2015第一题Cursed Query
英文题面: De Prezer loves movies and series. He has watched the Troy for like 100 times and also he is a ...
- 取出所有的Map集合
public static void main(String[] args) { Map<Integer, String> map = new HashMap<Integer, St ...
- Lua学习八----------Lua运算符
© 版权声明:本文为博主原创文章,转载请注明出处 1.Lua运算符: - 算术运算符:+(加法).-(减法).*(乘法)./(除法-取整).%(除法-取余).^(乘幂).-(负号) - 关系运算符:= ...
- HDU 2242 考研路茫茫——空调教室(边双连通)
HDU 2242 考研路茫茫--空调教室 题目链接 思路:求边双连通分量.然后进行缩点,点权为双连通分支的点权之和,缩点完变成一棵树,然后在树上dfs一遍就能得出答案 代码: #include < ...
- POJ 2985 Treap平衡树(求第k大的元素)
这题也能够用树状数组做,并且树状数组姿势更加优美.代码更加少,只是这个Treap树就是求第K大元素的专家--所以速度比較快. 这个也是从那本红书上拿的模板--自己找了资料百度了好久,才理解这个Trea ...
- 常用js特效
事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放 event.srcElement.setCapture(); event.sr ...