gpt4 book ai didi

socket.io - 通过 apache 代理运行 socket.io 的问题

转载 作者:行者123 更新时间:2023-12-04 10:29:03 24 4
gpt4 key购买 nike

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

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

VM6:1 POST https://comptonpeslonline.com/proxyPort20005/socket.io/?EIO=3&transport=polling&t=NX 400 (Bad Request)



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

[Mon Mar 02 18:25:03.199849 2020] [proxy:error] [pid 28494] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:20005 (localhost) failed

[Mon Mar 02 18:25:03.199892 2020] [proxy:error] [pid 28494] AH00959: ap_proxy_connect_backend disabling worker for (localhost) for 5s

[Mon Mar 02 18:25:03.199898 2020] [proxy_http:error] [pid 28494] [client 71.223.254.40:50269] AH01114: HTTP: failed to make connection to backend: 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":"Session ID unknown"}



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

我的 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>

有人对我接下来可能会尝试什么有任何建议吗?

非常感谢大家。

最佳答案

经过大量的时间和精力,我有两个解决方案:

##  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']
}
);

关于socket.io - 通过 apache 代理运行 socket.io 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60498087/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com