前两天折腾了下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的更多相关文章

  1. WebSocket :Nginx+WebSocket内部路由策略推送服务器的实现(附可生产环境应用代码)

    1.项目背景 前几天写了一篇WebSocket推送的博客:WebSocket :用WebSocket实现推送你必须考虑的几个问题 支持的连接数大概几千个,具体数量依赖于tomcat能并发的线程数,但很 ...

  2. Nginx websocket反向代理

    L:106 现在主流的反向代理,通过长链接可以从服务器推送数据到页面 升级成websocket反向代理必须根据上面的配置做配置 缺点无法多路复用,也就是没办法并行 我们测试下Websocket反向代理 ...

  3. tomcat 7下spring 4.x mvc集成websocket以及sockjs完全参考指南(含nginx/https支持)

    之所以sockjs会存在,说得不好听点,就是因为微软是个流氓,现在使用windows 7的系统仍然有近半,而windows 7默认自带的是ie 8,有些会自动更新到ie 9,但是大部分非IT用户其实都 ...

  4. Nginx反向代理websocket配置实例(官网)

    https://www.nginx.com/blog/websocket-nginx/ Blog Tech Rick Nelson of NGINX, Inc.   May 16, 2014   NG ...

  5. tomcat 7下spring 4.x mvc集成websocket以及sockjs完全参考指南

    之所以sockjs会存在,说得不好听点,就是因为微软是个流氓,现在使用windows 7的系统仍然有近半,而windows 7默认自带的是ie 8,有些会自动更新到ie 9,但是大部分非IT用户其实都 ...

  6. Nginx SPDY Pagespeed模块编译——加速网站载入

    在看<Web性能权威指南>的时候,看到了SPDY这货,于是便开始折腾起了这个了,也顺便把pagespeed加了进去. Nginx SPDY 引自百科~~ SPDY(读作“SPeeDY”)是 ...

  7. 实战http切换成https

    Server端使用Nginx + Tomcat Niginx SSL on Tomcat SSL non 步骤: 1.修改代码,将外部引用的http js css 文件修改为https,若外部链接不支 ...

  8. linuxWeb环境安装——小皮面板不错的面板

    安装环境为最新的:CentOS8.1.1911  linux的web环境安装,说白了,弄明白了就不难.为此阅读了多部文献,最先的是linux教程,重理论轻实践:之后,看了鸟哥的私房菜,有2本,每本都8 ...

  9. 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. ...

随机推荐

  1. 进程间通信(IPC)介绍(转)

    进程间通信(IPC,InterProcess Communication)是指在不同进程之间传播或交换信息. IPC的方式通常有管道(包括无名管道和命名管道).消息队列.信号量.共享存储.Socket ...

  2. 工厂方法模式之C++实现

    说明:本文仅供学习交流,转载请标明出处.欢迎转载. 工厂方法模式与简单工厂模式的差别在于:在简单工厂模式中.全部的产品都是有一个工厂创造,这样使得工厂承担了太大的造产品的压力,工厂内部必须考虑所以的产 ...

  3. java将一个或者多个空格进行分割

    public static void main(String[] args) { String s = "GET /index.html HTTP/1.1";//字符串s由“GET ...

  4. 3DES

    3DES是继DESeasy被破解后的DES加密升级版,它属于对称加密. 可指定24位长度的密钥.在java API中也有事实上现,代码例如以下: /** * 3DES 的Java SDK API 实现 ...

  5. ORA-02050故障诊断一例

    http://czmmiao.iteye.com/blog/1474678昨天客户反映说在下午某时间段有几个事务失败了,让我查下当时数据库系统的负载是否正常,看了下CPU的历史负载,很正常,于是看了下 ...

  6. 安装CoreOS到磁盘

    1 打开翻&&墙软件 2 打开迅雷,启用“使用IE代理”,下载以下两个文件:(翻&&墙后用IE下会中断) http://stable.release.core-os.n ...

  7. detect——point_in_polygon

    /******************实现功能:判断平面任一点是否在指定多边形内********************/ #include <string> #include <v ...

  8. HBase——完全分布

    实际上,在真实环境中你需要使用完全分布配置完整测试HBase.在一个分布式配置中,集群有多个节点,每个节点运行一个或多个HBase守护进程.其中包括主Master和备份Master实例,多个Zooke ...

  9. jquery判断复选框是否被选中

    $("#isUse").click(function(){ if($(this).is(':checked')){ $(this).attr('checked','checked' ...

  10. 查看SELinux状态并关闭SELinux

    SELinux(Security-Enhanced Linux)是Linux上最杰出的新安全子系统.在linux内核级别上提供了一个灵活的强制访问控制系统(MAC),这个强制访问控制系统是建立在自由访 ...