问题
Recently i moved from using port numbers to an apache proxy, and now i get the following browser console errors:
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)
and my apache log file is filling up with these messages:
[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/
--
I did find one interesting difference between using ports and proxies. using the port number, when I entered the following:
https://example.com:8005/socket.io/?EIO=3&transport=polling
these results came back in the browser window:
96:0{"sid":"XXXX","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000}
but when I tried the same using the proxy:
https://example.com/proxyPort20005/socket.io/?EIO=3&transport=polling
I see suspicious looking results, very different from when i used the port number:
{"code":1,"message":"Session ID unknown"}
the strange thing is that everything appears to be working fine, except for all the error messages.
my httpd.conf is configured like this:
## 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>
Does anybody have any suggestions on what i might try next?
thank you all very much.
回答1:
After much time and effort, i have two solutions:
## 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']
}
);
this works as well, however, I wanted both WebSockets and Polling working, this example only has polling:
<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']
}
);
来源:https://stackoverflow.com/questions/60498087/issues-running-socket-io-over-an-apache-proxy