015_NGINX作为WebSocket Proxy的设置
产研那边有通过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的设置的更多相关文章
- HTTP请求的python实现(urlopen、headers处理、 Cookie处理、设置Timeout超时、 重定向、Proxy的设置)
python实现HTTP请求的三中方式:urllib2/urllib.httplib/urllib 以及Requests urllib2/urllib实现 urllib2和urllib是python两 ...
- nodejs 转发websocket (websocket proxy)
const http = require('http') const server = http.createServer((req, res) =>{ res.end('hello world ...
- 五种ip proxy的设置方法
我们在制作爬虫爬取想要的资料时,由于是计算机自动抓取,强度大.速度快,通常会给网站服务器带来巨大压力,所以同一个IP反复爬取同一个网页,就很可能被封,在这里介绍相关的技巧,以免被封:但在制作爬虫时,还 ...
- urllib的实现---timeout,获取http响应码,重定向,proxy的设置
1.Timeout设置超时 只能修改Socket设置全局Timeout #! /usr/bin/env python3 import socket import urllib.request # ti ...
- 命令行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 ...
- JMeter怎样测试WebSocket,如何设置(一)
一.安装WebSocket取样器 1.从JMeter插件管理器官网下载:https://jmeter-plugins.org/ 把这6个jar包放到C:\JMeter\apache-jmeter-3. ...
- Apache proxy中转设置
参考http://sjsky.iteye.com/blog/1067119 打开http.conf (macOS中 Apache配置文件在/etc/apache2/中 etc是隐藏的) 确保下面 ...
- Selenium Chrome浏览器的启动以及proxy设置
Selenium Chrome浏览器的启动以及proxy设置 虽然WebDriver对Firefox的支持最好,之前写的脚本也都在Firefox浏览器运行,但最近项目做了整合,发现新整合的功能不太 ...
- 设置Proxy Server和SQL Server实现互联网上的数据库安全
◆首先,我们需要了解一下SQL Server在WinSock上定义协议的步骤: 1. 在”启动”菜单上,指向”程序/Microsoft Proxy Server”,然后点击”Microsoft Man ...
随机推荐
- Linux:进程实例信息(/proc)
https://blog.csdn.net/test1280/article/details/73632333 Linux:进程实例信息(/proc) 问几个问题: 1.怎么知道一个进程对应哪个可执行 ...
- HDU 1024 Max Sum Plus Plus (动态规划)
HDU 1024 Max Sum Plus Plus (动态规划) Description Now I think you have got an AC in Ignatius.L's "M ...
- JS数组冒泡排序&去重
冒泡排序: var a = [2,1,4,3,6,5]; for(var d = 0 ; d< a.length; d++){ for(var b = d+1; b < a.length; ...
- A1079. Total Sales of Supply Chain
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- A1010. Radix
Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...
- 【模板】Splay
Splay 均摊复杂度证明见此处 \(\rightarrow\) 链接 代码如下 #include <bits/stdc++.h> using namespace std; const i ...
- 过时date.toLocaleString()的解决方法
System.out.println(new java.util.Date()); 输出:Thu Jan 27 14:43:28 CST 2011 System.out.println(new jav ...
- Jenkins插件安装实战篇
Jenkins插件安装实战篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 上篇博客我介绍了Jenkins是啥,以及持续集成,持续交付,持续部署的概念,那么问题来了:你知道CI和C ...
- Scala进阶之路-Spark本地模式搭建
Scala进阶之路-Spark本地模式搭建 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Spark简介 1>.Spark的产生背景 传统式的Hadoop缺点主要有以下两 ...
- 函数和常用模块【day04】:函数参数及调用(二)
本节内容 1.为什么要有参数 2.返回值 3.有参数函数调用 一.为什么要有参数? 无参数实现 def CPU报警邮件() #发送邮件提醒 连接邮箱服务器 发送邮件 关闭连接 def 硬盘报警邮件() ...