In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
The following brings you what is Wesocket Load Balancer based on Nginx. I hope it can bring some help to you in practical application. Load Balancer involves many things, but there are not many theories. There are many books on the Internet. Today, we will use the accumulated experience in the industry to make an answer.
Share a NginxWesocket-based Load Balancer.
1. Install nginx on Mac PC
brew install nginx
2. After installation nginx configuration file path
/usr/local/etc/nginx/nginx.conf
3. Edit configuration files for configuration
In the http block
new configuration
#gzip on;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream ws_server {
server qa.server.com:2048;
server qa.server.ai:2048;
}
server {
listen 2048;
server_name localhost;
location /ws {
proxy_pass http://ws_server/ws;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
nginx listens on port 2048 and forwards requests to qa.server.h, qa.server.test
Client connects via this address: ws://localhost:2048/ws
There has been a question before, why should ws be proxied through http?
The handshake part of ws protocol borrows http protocol, and after the handshake is completed, the protocol is switched (upgrade of header part).
This View Network Connection
Request URL:
ws://localhost:2048/ws
Request Method:
GET
Status Code:
101 Switching Protocols
Response Headersview source
Connection:
upgrade
Date:
Fri, 15 Sep 2017 01:48:28 GMT
sec-websocket-accept:
r+ZclgKaM7r9b6RklYinaGUcvwE=
Server:
nginx/1.12.1
upgrade:
websocket
Request Headersview source
Accept-Encoding:
gzip, deflate, br
Accept-Language:
en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4
Cache-Control:
no-cache
Connection:
Upgrade
Host:
localhost:2048
Origin:
http://localhost:8000
Pragma:
no-cache
Sec-WebSocket-Extensions:
permessage-deflate; client_max_window_bits
Sec-WebSocket-Key:
yoh4s/VG9x099oJEoP4FNA==
Sec-WebSocket-Version:
13
Upgrade:
websocket
User-Agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
Read the above about what is Wesocket Load Balancer based on Nginx, if you still have anything to know, you can find something you are interested in the industry information or find our professional technical engineers to answer, technical engineers have more than ten years of experience in the industry.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.