0
votes

I want to run node.js and socket.io on the https. I redirect requests which are coming from server.example.com to http://example.com:3000

<VirtualHost server.example.com:80>
    ProxyPass / http://example.com:3000/
</VirtualHost>

And this way i can access to socket.io.js file

https://server.example.com/socket.io/socket.io.js

To test node.js part, print socket.id in console.

Image : http://prntscr.com/jq81bz

Here is the client side, i connect to socket.io with this way.

Image : http://prntscr.com/jq830z

The client connects node.js server and print the socket.id. But there are many errors occurred in browser console. I think the client wants to connect again because of errors.

Image : http://prntscr.com/jq82ib <- server's console is on left

Those logs printed for just one connection.

1

1 Answers

0
votes

You apache configurations must be changed as follow.

<VirtualHost *:443>
     ServerName mysite.com
     ServerAlias www.mysite.com

     SSLEngine on
     SSLProxyEngine On
     ProxyRequests Off

     SSLCertificateFile /etc/apache2/ssl/mysite.com.crt
     SSLCertificateKeyFile /etc/apache2/ssl/mysite.com.key
     SSLCertificateChainFile /etc/apache2/ssl/ca.cer

     DocumentRoot /var/www/errorPages

     ErrorDocument 503 /503.html
     ProxyPass /503.html !

     ProxyPass / http://localhost:3000/
     ProxyPassReverse / http://localhost:3000/


     RewriteEngine on
     RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
     RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
     RewriteRule .* ws://localhost:3000%{REQUEST_URI} [P]


</VirtualHost>