【问题标题】:Websockets behind Apache and Nginx proxy connection not upgradedApache 和 Nginx 代理连接后面的 Websockets 未升级
【发布时间】:2015-10-20 08:39:18
【问题描述】:

我有问题。 Apache 侦听白色 ip 并代理所有请求 /ssd 上的 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;
}
include /etc/nginx/conf.d/*.conf;

在 default.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;
 }

请求标头:

Connection: Upgrade
Upgrade: Websocket

响应标头:

Connection: close
Status Code 400 Bad Request

我做错了什么?

【问题讨论】:

  • 你设置了 mod_websocket 了吗?
  • 在最新版本的 apache (2.4.6+) 中存在 wstunnel 模块,我是通过 LoadModule 在我的 .conf 文件中添加的

标签: apache nginx proxy websocket


【解决方案1】:

请求中的授权标头呢?好像是授权问题。

【讨论】:

  • 您能检查连接和升级标头值吗?这些应该是连接头的升级和升级头的websocket。
  • 在请求中它是真的,但在响应中不存在这些标头
  • 这些对于握手请求已经足够了。你能在这里放更多关于请求的信息吗?它可能是损坏的标头或有效负载,但 websocket 握手不需要有效负载。
  • 请求: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
  • 回复:HTTP/1.1 400 Bad Request Date: Thu, 30 Jul 2015 20:46:15 GMT Server: nginx/1.8.0 Content-Type: text/html; charset=UTF-8 Content-Length: 54 Vary: Accept-Encoding Content-Encoding: gzip Via: 1.1 app-test.localdomain Connection: close
猜你喜欢
  • 2016-12-22
  • 2013-05-04
  • 2022-06-29
  • 2021-05-06
  • 1970-01-01
  • 2019-09-02
  • 2017-08-24
  • 1970-01-01
  • 2021-05-28
相关资源
最近更新 更多