【问题标题】:issues running socket.io over an apache proxy通过 apache 代理运行 socket.io 的问题
【发布时间】:2020-06-15 07:04:12
【问题描述】:

最近我从使用端口号转移到 apache 代理,现在我收到以下浏览器控制台错误:

VM6:1 GET https://comptonpeslonline.com/proxyPort20005/socket.io/?EIO=3&transport=polling&t=NX 400(错误请求)

VM6:1 POST https://comptonpeslonline.com/proxyPort20005/socket.io/?EIO=3&transport=polling&t=NX400(错误请求)

我的 apache 日志文件充满了这些消息:

[Mon Mar 02 18:25:03.199849 2020] [proxy:error] [pid 28494] (111)Connection denied: AH00957: HTTP: 尝试连接到 127.0.0.1:20005 (localhost) 失败

[Mon Mar 02 18:25:03.199892 2020] [proxy:error] [pid 28494] AH00959: ap_proxy_connect_backend 为 (localhost) 禁用工作器 5 秒

[Mon Mar 02 18:25:03.199898 2020] [proxy_http:error] [pid 28494] [client 71.223.254.40:50269] AH01114:HTTP:无法连接到后端:localhost,referer:https://example.com/proxyPort20005/

--

我确实发现了使用端口和代理之间的一个有趣的区别。使用端口号,当我输入以下内容时:

https://example.com:8005/socket.io/?EIO=3&transport=polling

这些结果在浏览器窗口中返回:

96:0{"sid":"XXXX","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}

但是当我尝试使用代理时:

https://example.com/proxyPort20005/socket.io/?EIO=3&transport=polling

我看到了可疑的结果,与我使用端口号时的结果大不相同:

{"code":1,"message":"会话 ID 未知"}

奇怪的是,除了所有错误消息之外,一切似乎都运行良好。

我的 httpd.conf 是这样配置的:

 ## 2020-03-02 - tried acquire
 ## 2020-03-02 - tried disablereuse=on
<Location /proxyPort20005/>
        ProxyPass http://localhost:20005/ Keepalive=On retry=5 timeout=600
        ProxyPassReverse http://localhost:20005/
</Location>

有人对我下一步可能尝试什么有任何建议吗?

非常感谢大家。

【问题讨论】:

    标签: socket.io


    【解决方案1】:

    经过很多时间和努力,我有两个解决方案:

    ##  thank you lopezdonaque @ https://github.com/socketio/socket.io/issues/1696
    
    RewriteEngine On 
    RewriteCond %{HTTP:Connection} Upgrade [NC]
    RewriteRule /proxyPort3030/(.*) ws://localhost:3030/$1 [P,L]
    
    <Location /proxyPort3030/>
        ProxyPass               http://localhost:3030/
                ## it seems to work fine without proxyPassReverse ??
        ProxyPassReverse        http://localhost:3030/
    </Location>
    
    const socket = io.connect
                (
                        {       'path'  : window.location.pathname + 'socket.io'
                        ,       'transports'    : ['websockets', 'polling']
                        }
                );
    

    这也可以,但是,我希望 WebSockets 和轮询都可以工作,这个例子只有轮询:

    <IfModule mod_proxy.c>
      <Proxy *>
        Order allow,deny
        allow from all
      </Proxy>
    </IfModule>
    
    ProxyPass          /proxyPort3030/                 http://localhost:3030/
    ProxyPassReverse   /proxyPort3030/                 http://localhost:3030/
    ProxyRequests off
    
    const socket = io.connect
                (
                        {       'path'  : window.location.pathname + 'socket.io'
                        ,       'transports'    : ['polling']
                        }
                );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      相关资源
      最近更新 更多