im trying to set up proxyng with apache to be able to use socket.io in my nodejs application. But i recieve this error message on the client side:
WebSocket connection to 'wss://example.com/tools/socket.io/?EIO=3&transport=websocket&sid=eOGwJSC14TTWhHRMAAAR' failed: Error during WebSocket handshake: Unexpected response code: 400
Heres my apache configuration:
<VirtualHost *:443>
ServerName example.com
ServerAlias example.com
#SSLRequireSSL
SSLProtocol all -SSLv2 -SSLv3
SSLCompression off
SSLHonorCipherOrder on
SSLEngine on
SSLCertificateFile /etc/ssl/main.pem
SSLCertificateKeyFile /etc/ssl/dec_ssl.key
SSLCertificateChainFile /etc/ssl/sub.class1.server.ca.pem
SSLCACertificateFile /etc/ssl/main.pem
SSLProxyEngine On
ProxyPreserveHost On
ProxyRequests off
</VirtualHost>
<Location /tools/>
ProxyPass http://localhost:8181/
ProxyPassReverse http://localhost:8181/
</Location>
And here is client side code:
socket = io.connect("https://example.com",{path:'/tools/socket.io'});
socket.on("connect", function () {
console.log("socketio Connected to server!");
});
What else i need to add to apache configuration to get rid of this error?
EDIT: My apache version: Server version: Apache/2.4.6 (CentOS)
As said before, Socket.IO can fall back to technologies other than WebSockets when the client doesn't support it. If (for some reason) a WebSocket connection drops, it will not automatically reconnect… but guess what? Socket.IO handles that for you! Socket.IO APIs are built to be easier to work with.
Socket.IO typically uses WebSockets as its transport layer, but sometimes uses HTTP "long-polling" as a fallback when WebSockets can't be used.
Socket.IO primarily uses the WebSocket protocol with polling as a fallback option, while providing the same interface.
Once you reboot your machine, you will now be able to happily go to 55k concurrent connections (per incoming IP).
I have added below as per @Gary
<Location /tools/>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/tools/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule "/(.*)" "ws://localhost:8181/socket.io/" [P,L]
ProxyPass http://localhost:8181/
ProxyPassReverse http://localhost:8181/
</Location>
and connect socket from client side using path attribute.
discussionSocket = io("https://localhost.in", {
path:'/tools/socket.io',
secure: true,
reconnection: true,
reconnectionDelay: 1000,
reconnectionDelayMax: 5000,
reconnectionAttempts: 99999
});
But for that we have to remove ssl configuration from socket server create code :-
var http = require('http').Server(app);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With