本文主要是介绍nginx反向代理配置以支持websock通信,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
作者:fyupeng
技术专栏:☞ https://github.com/fyupeng
项目文档:☞ https://rnf.cool
项目同步地址:☞ 预览
在nginx的conf/nginx.cnf配置文件中,配置http模块
和server代理模块
。
配置 http 模块
添加变量$http_upgrade
和 $connection_upgrade
map $http_upgrade $connection_upgrade { default keep-alive; #默认为keep-alive 可以支持 一般http请求'websocket' upgrade; #如果为websocket 则为 upgrade 可升级的。}
配置 server 代理模块
引用变量
server {listen 80;server_name localhost;location / {proxy_pass http://localhost:8080/;# support websocketproxy_set_header Upgrade $http_upgrade; #此处配置 上面定义的变量proxy_set_header Connection $connection_upgrade;}
}
这篇关于nginx反向代理配置以支持websock通信的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!