作者:fyupeng
技术专栏:? https://github.com/fyupeng
项目文档:? https://rnf.cool
项目同步地址:? 预览
在nginx的conf/nginx.cnf配置文件中,配置http模块
和server代理模块
。
添加变量$http_upgrade
和 $connection_upgrade
http{
map $http_upgrade $connection_upgrade {
default keep-alive; #默认为keep-alive 可以支持 一般http请求
'websocket' upgrade; #如果为websocket 则为 upgrade 可升级的。
}
}
引用变量
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost:8080/;
# support websocket
proxy_set_header Upgrade $http_upgrade; #此处配置 上面定义的变量
proxy_set_header Connection $connection_upgrade;
}
}