3

I hosted my website on an EC2 instance, using Apache. SSL was also set up properly, running on HTTPS, port 443.

Currently, I just added a chat application to the website using Node.js + socket.io. The Node.js server listen on port 3333.

How can I run the two servers (Apache and Node.js) on the same instance with SSL secured? Amazon EC2 doesn't allow me to open another port for HTTPS. It only allows 443 for HTTPS.

  • I can't write a detailed enough solution to post an answer right now, but you should check out stackoverflow.com/questions/10440965/… and gist.github.com/kassius/954e0787d6893c5ab8e1 – austinian Aug 20 '15 at 0:08
  • You can open any port on EC2 and use it for HTTPS traffic. When adding that to the security group select 'Custom TCP Rule' and enter 3333 for the port. If you want to host both on 443 and have them answer to different host names the simplest solution would be to front both with nginx. Move Apache to 3334 and put nginx on 443. You can set up nginx to send requests for one domain to Apache and the other to Node. It will use SNI for negotiating SSL. I've set this up before and it works well. – Nathan V Aug 26 '15 at 18:46
0

You don't need to open an additional port for anything. You can just set up a new virtualhost with a new ServerName using the ProxyPass directive to direct the incoming SSL traffics to your local Node.js server.

For example:

<VirtualHost *:443>
        ServerName nodeapp.com
        ServerAlias www.nodeapp.com app.nodeapp.com
        ServerAdmin webmas@localhost
        DocumentRoot /not/that/important

        SSLEngine on
        SSLCertificateFile      /path/to/cert
        SSLCertificateKeyFile   /path/to/key


        ProxyRequests off
        ProxyPass "/" "http://127.0.0.1:3333/"
        ProxyPassReverse "/" "http://127.0.0.1:3333/"

        ErrorLog ${APACHE_LOG_DIR}/nodeapp_error.log
        CustomLog ${APACHE_LOG_DIR}/nodeapp_access.log combined

</VirtualHost>

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.