网络问题连不上服务器,因此选了一台机子专门用于转发,安装nginx完毕后,编辑配置文件
vim /etc/nginx/nginx.conf
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream websocket {
#ip_hash;
#转发到服务器上相应的ws端口
server 1.2.3.4:9944;
}
server {
#listen后面的端口号改为你自己需要的端口号
listen 9944;
#server_name改为你自己的外网ip。server_name默认为localhost即127.0.0.1
server_name 192.168.103.180;
location / {
#转发到http://websocket
proxy_pass http://websocket;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#升级http1.1到 websocket协议
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
然后重载配置
nginx -s reload
网友评论