产研那边有通过nginx代理进行长连接的需求,咱们都知道默认nginx只支持短连接的,使用长连接需要单独配置

一、

websocket协议提供创建一种支持在server和client之前双向通信的web应用。作为HTML5的一部分,websock使比它之前可用的方式中提供一个种更加简单的方法。大部分现在的浏览器都支持websock,包括chrome,Firefox,Internet浏览器,Opera,和Safari,和越来越多的服务器应用框架也开始支持websock了。

The WebSocket protocol is different from the HTTP protocol,但是websocket握手是兼容http的,用TTP Upgrade方式更新从HTTP到websock的连接。This allows WebSocket applications to more easily fit into existing infrastructures.例如,websock应用能使用标准的http端口80和443进行通信。

A WebSocket application keeps a long‑running connection open between the client and the server, facilitating the development of real‑time applications. 这个 HTTP Upgrade 机制通过使用" the Upgrade and Connection headers." 来更新从HTTP到websocket的连接。There are some challenges that a reverse proxy server faces in supporting WebSocket. 一个是websocket是一个中hop-by-hop(逐跳)协议, so when a proxy server intercepts an Upgrade request from a client it needs to send its own Upgrade request to the backend server, including the appropriate headers. 还有,websocket连接是长连接,相反使用http时典型的短连接,即反向代理server需要在它们在空闲的时候需要保持这些连接保持open,而不是关闭它们。

NGINX supports WebSocket by allowing a tunnel to be set up between a client and a backend server. 对于nginx发送upgrade请求从client到后端的server, the Upgrade and Connectionheaders must be set explicitly, as in this example:

location /wsapp/ {
proxy_pass http://wsbackend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}

Once this is done, NGINX deals with this as a WebSocket connection.

二、举个栗子。

参考:https://www.nginx.com/blog/websocket-nginx/

015_NGINX作为WebSocket Proxy的设置的更多相关文章

  1. HTTP请求的python实现(urlopen、headers处理、 Cookie处理、设置Timeout超时、 重定向、Proxy的设置)

    python实现HTTP请求的三中方式:urllib2/urllib.httplib/urllib 以及Requests urllib2/urllib实现 urllib2和urllib是python两 ...

  2. nodejs 转发websocket (websocket proxy)

    const http = require('http') const server = http.createServer((req, res) =>{ res.end('hello world ...

  3. 五种ip proxy的设置方法

    我们在制作爬虫爬取想要的资料时,由于是计算机自动抓取,强度大.速度快,通常会给网站服务器带来巨大压力,所以同一个IP反复爬取同一个网页,就很可能被封,在这里介绍相关的技巧,以免被封:但在制作爬虫时,还 ...

  4. urllib的实现---timeout,获取http响应码,重定向,proxy的设置

    1.Timeout设置超时 只能修改Socket设置全局Timeout #! /usr/bin/env python3 import socket import urllib.request # ti ...

  5. 命令行command line 使用 http proxy的设置方法 Setting Up HTTP Proxy in Terminal

    Step 1: Install Shadowsocks Client Shadowsocks is an open-source proxy project to help people visit ...

  6. JMeter怎样测试WebSocket,如何设置(一)

    一.安装WebSocket取样器 1.从JMeter插件管理器官网下载:https://jmeter-plugins.org/ 把这6个jar包放到C:\JMeter\apache-jmeter-3. ...

  7. Apache proxy中转设置

    参考http://sjsky.iteye.com/blog/1067119 打开http.conf  (macOS中 Apache配置文件在/etc/apache2/中   etc是隐藏的) 确保下面 ...

  8. Selenium Chrome浏览器的启动以及proxy设置

    Selenium Chrome浏览器的启动以及proxy设置   虽然WebDriver对Firefox的支持最好,之前写的脚本也都在Firefox浏览器运行,但最近项目做了整合,发现新整合的功能不太 ...

  9. 设置Proxy Server和SQL Server实现互联网上的数据库安全

    ◆首先,我们需要了解一下SQL Server在WinSock上定义协议的步骤: 1. 在”启动”菜单上,指向”程序/Microsoft Proxy Server”,然后点击”Microsoft Man ...

随机推荐

  1. libcurl使用easy模式阻塞卡死等问题的完美解决

    引言: 由于要在android手机测进行DM开发, 其中最重要的就是FUMO和SCOMO下载, 下载使用的是linux开源库libcurl. 于是就把libcurl的使用研究了一遍, 有些心得, 并解 ...

  2. CF1080

    emmmm......ouuan大佬上紫了,我却没打...... 首先吐槽一波家长会和机房锁门,害我只能来打虚拟赛. 写了abcd四题,还是被ouuan大佬吊打....... 264名,应该能上分吧. ...

  3. P3747 相逢是问候 欧拉定理+线段树

    巨难!!! 去年六省联考唯一的一道黑牌题,我今天一天从早到晚,把它从暴力15分怼到了90分,极端接近正解了. bzoj上A了,但是洛谷和loj上面就不行.伪正解会T,奇奇怪怪的类正解会WA.. 那么, ...

  4. ASP: Response 对象 错误 'ASP 0251 : 80004005' 解决办法

    Response 对象 错误 'ASP 0251 : 80004005' 超过响应缓冲区限制 这种情况一般是因为需要输出的网页内容太大了,由于asp在输入内容到客户的浏览器上之前,会把需要输出的全部内 ...

  5. git branch 分支管理

    在多人协作的情况下,master通常是稳定的分支.可以再建一些"develop","testing"等名称的分支.主管master的人做开发的话最好也建立自己的 ...

  6. gradle下载的依赖包位置 及 修改

    gradle下载的依赖包位置 2018年08月01日 00:37:06 LuckyJiang-2019 阅读数:3569   Mac系统默认下载到: /Users/(用户名)/.gradle/cach ...

  7. NO.8:绝不在构造或者析构过程中调用virtual函数

    在构造和析构执行期间不要调用virtual函数,因为这类调用从不会下降至derived class(比起当前执行构造函数和析构函数) 如果在base class 构造函数或者析构函数调用virtual ...

  8. CSS的显示模式

    div与span div与span有什么区别 div单独占一行,span不会单独占一行 div是容器级的标签,而span是一个文本级的标签 容器级的标签有:div , h , ul , ol , dl ...

  9. H5新特性之canvas

    canvas无疑是H5之中最受欢迎的新特性了,它可以让浏览毫无费力的画出各种图案,动画. canvas的性能不会因为画布上的图案多少而改变,因此做动画用canvas性能也相当优秀. canvas最基本 ...

  10. 原生ajax写法

    ajax1.0,ie9及以下,ie10+支持ajax2.0 ajax2.0比ajax1.0: 1.多了FormData对象,xhr.send(formData)  //不能用GET 2.文件上传,文件 ...