【发布时间】:2015-04-20 04:06:46
【问题描述】:
我在通过 Apache (2.4.6) 代理我的 WebSocket 连接 (Socket.io) 时遇到问题。我正在尝试使用 Socket.io 问题https://github.com/Automattic/socket.io/issues/1696 中描述的设置,但我的开发人员工具中不断收到错误消息,即在 WebSocket 握手期间连接失败:
WebSocket connection to 'ws://example.domain.com/socket.io/?EIO=3&transport=websocket&sid=KPd7VBy4Yi7mj-wAAABN' failed: Error during WebSocket handshake: 'Connection' header value must contain 'Upgrade'
这是因为Connection 标头设置为Close 而不是Upgrade。
我已经确认 proxy_wstunnel_module 模块已加载,当我查看跟踪日志时,我可以看到它响应了一些请求,但我仍然收到上述错误。我绝对不是 Apache 专家,所以我认为我的 httpd.conf 文件中有些地方不正确(我尝试使用 Apache 文档确认所有行。
<VirtualHost *:80>
ServerName example.domain.com
ServerAlias example.domain.com
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET, POST, OPTIONS"
Header set Access-Control-Allow-Headers "content-type,x-requested-with"
RewriteEngine on
RewriteRule ^/$ /otherApp/home [PT]
RewriteCond %{REQUEST_URI} ^/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=polling [NC]
RewriteRule /(.*) http://localhost:3000/$1 [P,L]
<Directory />
Options All
Order Deny,Allow
Allow from all
</Directory>
ProxyRequests off
<Proxy *>
Order Deny,Allow
Allow from all
</Proxy>
<Location />
Order Deny,Allow
Allow from all
</Location>
ProxyPass /socket.io ws://localhost:3000/socket.io
ProxyPassReverse /socket.io ws://localhost:3000/socket.io
ProxyPass /AnotherApp ajp://localhost:8009/location
ProxyPass /AnotherApp2 ajp://somewhere.else:8009/location2
DocumentRoot /opt/appThings
<Directory /opt/appThings>
Options +Indexes
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
有人在我上面的httpd.conf 文件中看到任何会导致此问题的明显内容吗?
如果需要其他相关信息,请告诉我。我查看了日志,但我不完全确定什么是相关的/我需要寻找什么。
【问题讨论】: