Apache 2.4 ProxyPass Configuration
Problem
With 0.9 I was able to proxy our websockets through Apache 2.4 using the following config: [code block] I'm attempting to migrate to 1.0.6 now and I immediately noticed that the socket endpoint changed, but updating the ProxyPass config like so does not seem to do the trick. [code block] Chrome reports over and over again that it receives a 400 error when trying to open the websocket. There's no output in the console on the server to indicate that any connection attempt was received (DEBUG=socket.io). Is there some other configuration factor that I need for this to work?
Error Output
error when trying to open the websocket. There's no output in the console on the server to indicate that any connection attempt was received (DEBUG=socket.io).
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Apache 2.4 ProxyPass Configuration
Although not ideal, I managed to make it work without modifying socket.io by using a combination of Apache's mod_rewrite to check the transport query string parameter, and if it's set to "polling" proxy to the http url, otherwise proxy to the ws: url. Rewriting to the ws: protocol with a RewriteRule did not seem to work correctly here, so therefore ProxyPass was still necessary. Here's the code,
Trust Score
5 verifications
- 1
Although not ideal, I managed to make it work without modifying socket.io by usi
Although not ideal, I managed to make it work without modifying socket.io by using a combination of Apache's mod_rewrite to check the transport query string parameter, and if it's set to "polling" proxy to the http url, otherwise proxy to the ws: url. Rewriting to the ws: protocol with a RewriteRule did not seem to work correctly here, so therefore ProxyPass was still necessary.
textRewriteEngine on RewriteCond %{QUERY_STRING} transport=polling RewriteRule /(.*)$ http://localhost:3000/$1 [P] ProxyRequests off ProxyPass /socket.io/ ws://localhost:3000/socket.io/ ProxyPassReverse /socket.io/ ws://localhost:3000/socket.io/ - 2
Here's the code, for a socket.io server on port 3000:
Here's the code, for a socket.io server on port 3000:
Validation
Resolved in socketio/socket.io GitHub issue #1696. Community reactions: 11 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep