This is my thrid blog web site.

0%

nginx-reverse-proxy

Nginx 反向代理支持websocket

记录一下域名反向代理的nginx配置

环境

1
2
uname -a # Linux VM-8-3-ubuntu 5.4.0-77-generic #86-Ubuntu SMP Thu Jun 17 02:35:03 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
nginx -v # nginx version: nginx/1.18.0 (Ubuntu)

nginx配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

upstream wss_svr {
server 127.0.0.1:8080;
}

map $http_upgrade $connection_upgrade {
default keep-alive;
'websocket' upgrade;
}

server {
listen 80;
server_name aaa.bbb.ccc;

location / {
proxy_http_version 1.1;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real_IP $remote_addr;
proxy_pass http://wss_svr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwared-For $proxy_add_x_forwarded_for;
}
}