我正在尝试为WebSocket聊天应用设置代理服务器,但客户端告诉我它无法与代理建立连接。我对WebSockets很陌生,所以我可能错过了一些东西。
我目前的设置如下:
我已将以下行添加到WampServer的httpd.conf文件中:
Listen 0.0.0.0:6060
Listen [::0]:6060
ServerName localhost:6060
# block anyone but localhost from accessing my computer's C: drive
<Directory />
Options FollowSymLinks
AllowOverride none
Order Deny,Allow
Deny from all
Allow from 127.0.0.1 ::1
Require all denied
</Directory>
# set up a proxy on port 6060,forwarding any WebSocket requests to port 8080
<VirtualHost *:6060>
ServerName proxyTestServer
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /ws/ ws://[IPADDRESS]:8080/Chatroom/chatroom/
ProxyPass /wss/ wss://[IPADDRESS]:8080/Chatroom/chatroom/
ProxyPassReverse /ws/ ws://[IPADDRESS]:8080/Chatroom/chatroom/
ProxyPassReverse /wss/ wss://[IPADDRESS]:8080/Chatroom/chatroom/
</VirtualHost>
客户端中的WebSocket使用普通的JavaScript定义如下:
chatSocket = new WebSocket("wss://[IPADDRESS]:6060");
Firefox 35和Chrome 40都无法连接到代理。这让我怀疑我的地址错误或者代理配置不正确(尽管Wampserver没有显示任何错误)。就像我在顶部说的那样,我对WebSockets很陌生,所以我很可能忽略了一些东西。
更新(2015年2月2日):在查看mod_proxy文档后,我更改了配置文件,以便服务器和客户端通过端口80进行通信,以及以下内容。但是,这没效果。
ProxyRequests Off
ProxyPass /chatProxy/ ws://localhost:8080/ChatProxy/ChatProxy/
ProxyPassReverse /chatProxy/ ws://localhost:8080/ChatProxy/ChatProxy/
ProxyPass /chatProxy/ wss://localhost:8080/ChatProxy/ChatProxy/
ProxyPassReverse /chatProxy/ wss://localhost:8080/ChatProxy/ChatProxy/
答案 0 :(得分:0)
我设法解决了这个问题:
ws://ProxyIP:6060/chatProxy
我的代理具有以下配置:
# The proxy listens to a specific IP address
Listen [ProxyIP]:6060
ServerName [ProxyIP]:6060
<VirtualHost *:6060>
ServerName proxyserver
ProxyRequests Off
ProxyPreserveHost On
ProxyVia On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# anything on port 6060 which ends in /chatProxy will be redirected
<Location /chatProxy>
ProxyPass ws://MyIP:8080/ChatProxy/ChatProxy
ProxyPassReverse ws://MyIP:8080/ChatProxy/ChatProxy
# wss is similar, but obviously prefaced by wss instead of ws
</Location>
</Virtual Host>
我现在还不完全确定为什么会这样,但我注意到如果客户端使用WebSocketSecure连接它不起作用。所以,我可能还没有正确配置SSL,但我想我可以在以后解决这个问题。