4

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.

2
  • 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 Commented Aug 20, 2015 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. Commented Aug 26, 2015 at 18:46

1 Answer 1

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> 
1
  • Also, don't forget to enable mod_proxy under Apache2. Debian flavors example = sudo a2enmod proxy proxy_html && sudo systemctl restart apache2 -- mod_proxy ref: httpd.apache.org/docs/2.4/mod/mod_proxy.html Commented Nov 17, 2019 at 15:38

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.