Apache 和 Nginx 代理连接背后的 Websockets 未升级

Apache 和 Nginx 代理连接背后的 Websockets 未升级

我遇到了一个问题。Apache 监听一个白色 IP,并将所有请求 /ssd 代理到 nginx,而 nginx 又将请求 /city-dashboard 代理到另一台带有 websockets 的服务器。在 apache 配置中:

ProxyPass /ssd/ http://10.127.32.24
ProxyPassReverse /ssd/ http://10.127.32.24

nginx 配置:在 nginx.conf 上:

 map $http_upgrade $connection_upgrade {
   default upgrade;
   ''      close;

} 在 default.conf 上包含 /etc/nginx/conf.d/*.conf;

 location /city-dashboard/stream {
     proxy_pass http://10.127.32.24:5000/stream;
     proxy_set_header Host $host;
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection $connection_upgrade;
 }

请求标头:

GET ws://x.x.x.x/ssd/city-dashboard/stream HTTP/1.1 
Host: x.x.x.x 
Connection: Upgrade 
Pragma: no-cache 
Cache-Control: no-cache 
Upgrade: websocket 
Origin: http://x.x.x.x 
Sec-WebSocket-Version: 13 
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36 
Accept-Encoding: gzip, deflate, sdch 
Accept-Language: en-US,en;q=0.8 
Sec-WebSocket-Key: 881o9c/z3Q437JFCti3BIw== 
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits

响应标头:

Connection:Upgrade, close
Content-Length:34
Content-Type:text/html; charset=UTF-8
Date:Wed, 19 Aug 2015 16:53:40 GMT
Server:nginx/1.8.0
Upgrade:websocket

Connection: close

状态代码 400 错误请求 我做错了什么?我认为 apache 或 nginx 可能剪切了标头,如何才能让它们不剪切呢?

我尝试在 apache conf 上这样写:

Header set Connection "Upgrade"
RequestHeader setifempty Connection "Upgrade"
Header set Upgrade "websocket"
RequestHeader setifempty Upgrade "websocket"

相关内容