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 ...
随机推荐
- 洛谷P4043 支线剧情
题意:给定DAG,通过每条边需要时间. 从某号点回到1号点不需要时间. 从1号点出发,求最少要多久才能走完所有边. 解: 有源汇有上下界最小费用可行流. 直接连边,费用为时间,下界为1,无上界. 每个 ...
- 【codevs2189】数字三角形+
题目大意:给定一个数字三角形,求从 (1,1) 走到最后一行的路径和对 100 取余数的最大值. 题解:由于最优解涉及到取余数的操作,因此按照原先的状态设计并不符合最优子结构性质,即:两个最大数相加取 ...
- SQL: 从一个表随机读取一行或几行记录的问题
比如ms sql 2000,随机读取了一行记录: SELECT TOP 1 * FROM [tablename] ORDER BY NEWID() 遇到的问题是,如果这个表记录不多,比如几十或几百.几 ...
- 牛客练习赛29 F 算式子
https://www.nowcoder.com/acm/contest/211/F 经典题. 1.分区间 2.向下取整的值变化 & 合并相同值 #include <bits/stdc+ ...
- JAVA实现SFTP实例
最近写的一个JAVA实现SFTP的实例: /* * Created on 2009-9-14 * Copyright 2009 by www.xfok.net. All Rights Reserved ...
- java自带BASE64工具进行图片和字符串转换【转】
java自带BASE64工具进行图片和字符串转换 import java.io.File; import java.io.FileInputStream; import java.io.FileOut ...
- HashMap分析及散列的冲突处理
1,Hashing过程 像二分查找.AVL树查找,这些查找算法的时间复杂度为O(logn),而对于哈希表而言,我们一般说它的查找时间复杂度为O(1).那它是怎么实现的呢?这就是一个Hashing过程. ...
- Hammer.js 移动端手势库,多点触控插件
jquery用法: 引入3个JS:<script src="jquery.js"></script> <script src="hammer ...
- C# 部分类使用partial修饰
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace pati ...
- Seafile 网络磁盘
Seafile 个人 网盘 1.安装 Seafile 1.安装依赖环境 使用 yum 安装 Python 及 MySQL: yum install python python-setuptools p ...