产研那边有通过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. Azure Powershell script检测登陆并部署ARM Template

    本文简单提供了一个Azure powershell脚本,能实现如下功能 Azure (China)账户是否已经登陆了,如果没登陆,会提示你登陆. 要创建的资源组是否存在,存在的话不再创建,直接部署te ...

  2. SwitchButton 开关按钮 的多种实现方式 (附源码DEMO)

    http://blog.csdn.net/vipzjyno1/article/details/23707149 Switch开关android源码SwitchButton 刚开始接触开关样式的按钮是在 ...

  3. centos6.5安装VNC、远程及启动关闭

    标签: centos vnc 远程桌面 安装 详解 0.说明 安装服务的过程当中,最好是在联网环境下操作.由于涉及到远程连接的问题,系统的防火墙需要关闭,或者是做好相应的过滤策略.参考了网上很多大牛的 ...

  4. bracketed-paste-magic:zle:41: not enough arguments for -U

    原因是zsh的插件出问题了,解法方法如下: 把 ~/.oh-my-zsh/lib/misc.zsh 文件中的第一段 if 注释掉 OK 啦 # ]]; then # for d in $fpath; ...

  5. js变量浅谈

    js变量是除了this以外最让人恶心的东西了,还因为烂语法造成各种各样奇奇怪怪的事情发生,下面让我们来谈谈都有什么奇怪的事: 1.用var与不用var function test(){ a = 123 ...

  6. C# 新特性

    1.字符串中调用参数 DataTable dt= sqlHelper.SqlConnectionInformation(connstr,sql); string rows = JsonConvert. ...

  7. EXISTS 与 NOT EXISTS 的用法及返回结果

    (1)SELECT * FROM `datatower-all`.TMP_DWD_POI t1 WHERE EXISTS ( SELECT 1 FROM `datatower-all`.DWD_POI ...

  8. <!--more-->搭建的博客设置主页内容高度

    用 markdown写文章时插入<!--more-->,文章会自动从插入的位置截断,也就是说在博客中只显示<!--more-->之前的内容,点击阅读全文之后会显示所有内容.

  9. Kanboard简单的可视化任务板,项目管理

    采用docker安装 简单快捷 下载 docker pull kanboard/kanboard:latest 运行 docker run -d --name kanboard -p 10080:80 ...

  10. mvn依赖冲突

    https://www.cnblogs.com/twoheads/p/10082453.html