【问题标题】:How to configure Wampserver to act as a WebSocket proxy?如何配置 Wampserver 作为 WebSocket 代理?
【发布时间】: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


    【解决方案1】:

    我设法解决了这个问题:

    • 客户端托管在我的机器上,端口为 6060。
    • 后端服务器是一个 Java servlet(注释为“ChatProxy”),通过 Glassfish 在我的机器上的 8080 端口运行。
    • 代理服务器在另一台机器上,它侦听端口 6060。
    • 客户端使用标准 WebSocket连接,即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,但我想我可以稍后解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-13
      • 2020-01-25
      • 1970-01-01
      • 1970-01-01
      • 2014-01-11
      • 1970-01-01
      • 2023-04-09
      • 2017-05-05
      相关资源
      最近更新 更多