首页 > 解决方案 > Nginx $http_upgrade 始终为空

问题描述

我有一个 websocket 程序,我使用 nginx 作为路由器。问题是 websocket 需要 Upgrade 标头才能正常工作。我确定我的 nginx 配置是正确的,并且我的程序运行正常。(我用本地主机测试)。细节和证据?我把它留在下面。我希望找到解决方案

相关配置;

proxy_set_header Upgrade $http_x_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header UpgradeTest $http_upgrade+"_test"; #for be sure
proxy_set_header UpgradeXTest $http_x_upgrade+"_test"; #for be sure
proxy_set_header Connection "Upgrade"; #this is ok

要求;

curl -v 'https://mywebsocketserver.example/abc' -H 'Upgrade: websocket' -H 'Connection: Upgrade' -H "TestHeader: IAmHere"

响应(标题)(go-map);

map[
         Testheader: IAmHere
         Accept: */*
         Accept-Encoding: gzip
         Cdn-Loop: cloudflare
         Cf-Connecting-Ip: <myip>
         Cf-Ray: 65a1b1ff3a30fd66-ATH
         Cf-Request-Id: 0a78ef738d0000fd66e76a8000000
         Cf-Visitor: {"scheme":"https"}
         Connection: Upgrade
         Demote-Host: <myip>
         Upgradetest: +"_test"
         Upgradextest: +"_test"
         User-Agent: curl/7.76.0
         X-Forwarded-Proto: https
         X-Real-Ip: <myip>
]

那么,我的 Upgrade [$http_upgrade] 标头在哪里 :)

标签: nginxwebsocketnginx-reverse-proxy

解决方案


推荐阅读