【发布时间】:2015-04-01 11:09:13
【问题描述】:
我正在尝试为 WebSocket 聊天应用程序设置代理服务器,但客户端告诉我它无法建立与代理的连接。我对 WebSockets 很陌生,所以我可能错过了一些东西。
我目前的设置如下:
- 操作系统:Windows 7 64 位
- 代理:localhost,端口 6060。这使用 Wampserver 2.5 和 Apache 2.4.9,包括所需的模块(mod_proxy、mod_proxy_wstunnel)
- 目标服务器:localhost,端口 8080。这使用 Glassfish 4.0
- 服务器端点:Java 1.7,配置为使用 Glassfish
- 客户端:使用 JavaScript 的 HTML5 页面
我在 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/
【问题讨论】:
标签: html proxy websocket wampserver reverse-proxy