Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache and NodeJS over SSL

I need to switch from HTTP to HTTPS to be able to use the getUsermedia for webrtc implementation. I've installed certificates on my Apache version 2.2.22 and got it working.

In the website I'm hosting NodeJS is used. Perhaps not the ideal setup but I've encountered problems when socket.io on the client wants to communicate with the NodeJS server.

In the console this message appears:

GET https://mydomain.nl:1900/socket.io/?EIO=3&transport=polling&t=1449219985177-166 net::ERR_CONNECTION_CLOSED 

It's obvious to me that the NodeJS server app can't handle requests over HTTPS because it's an HTTP server.

I want to alter that server to be able to serve HTTPS requests using the SSL already in place on the apache webserver.

Is this possible at all?

like image 420
ingridsede Avatar asked Dec 04 '15 09:12

ingridsede


People also ask

Can I use Apache with node js?

The benefits Apache brings to Node. js applications. How to configure Apache for a Node.

Does Apache use SSL?

The Apache HTTP Server module mod_ssl provides an interface to the OpenSSL library, which provides Strong Encryption using the Secure Sockets Layer and Transport Layer Security protocols.

Does Nodejs replace Apache?

If you're prepared to re-write your PHP in JavaScript, then yes, Node. js can replace your Apache. If you place an Apache or NGINX instance running in reverse-proxy mode between your servers and your clients, you could handle some requests in JavaScript on Node.


1 Answers

I recommend to have a look apache's mod_proxy. This would allow you to run the external requests over the apache SSL pipeline. The node.js can run only on the localhost interface without ssl support because it's proxy'd by apache. I you configure a vhost it could look like this:

<VirtualHost *:443>
  ServerName www.yourserver.com
  DocumentRoot /var/www/vhosts/www.yourserver.com/public_html

  CustomLog <LOG-PATH> combined
  ErrorLog <ERROR-LOG-PATH>

  # Example SSL configuration
  SSLEngine on
  SSLProtocol all -SSLv2
  SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
  SSLCertificateFile "<CERT-PATH>/server.crt"
  SSLCertificateKeyFile "<CERT-PATH>/server.key"

  ProxyPass /<PATH>/ http://localhost:1900/
  ProxyPassReverse /<PATH>/ http://myserver:1900/
</VirtualHost>

Your reguest would then look like this:

GET https://mydomain.nl/<PATH>/?.... 

Where <PATH> has the same value as in the vhost config's <ProxyPass> directive.

like image 200
frank Avatar answered Oct 05 '22 23:10

frank