一、需求說明
基于Nginx代理nginx.conf配置——反向代理,如果要添加websocket支持,需要進(jìn)行如下配置
二、配置內(nèi)容
在http中添加一下配置,添加對websocket支持
http {
# 配置其它內(nèi)容
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# 配置其它server
server {
listen 9016;
server_name localhost;
location /ws {
proxy_pass http://xxx.xxx.xxx.xxx:9016/ws;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
}
三、配置結(jié)果
配置后重新運(yùn)行nginx后,websocket即可成功代理。注意防火墻端口是否開放、nginx如果使用docker,其對應(yīng)的端口是否映射出來。文章來源:http://www.zghlxwxcb.cn/news/detail-542563.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-542563.html
到了這里,關(guān)于Nginx代理nginx.conf配置——反向代理(對WebSocket支持)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!