0
votes

We are using a combination of Apache Server and NodeJs (Express) for a website. Without SSL, the Apache used to listen to port 80 and Nodejs to port 8080.

Now, I am installing SSL on the website. The Apache is set to listen to port 443. I tried to make the Nodejs listen to port 8443, 3333 etc. - setting the AWS Security Group as "Custom TCP" for the port. The problem is I am not getting any response from the Nodejs server.My hunch is that the problem is with the EC2 security group setting but cannot really put a finger on the exact issue.

The server is created for Nodejs as following :

var https = require('https');
var fs = require('fs');
...
...
var https_options = {
        ca: fs.readFileSync ("/path/to/cabundle.ca-bundle", "utf8"),
        key: fs.readFileSync("/path/to/sslkey.key", "utf8"),
        cert: fs.readFileSync("/path/to/certificate.crt", "utf8")
};


var app = express();
var server = https.createServer(https_options, app);
....
....
server.listen(8443 or 3333);

Starting the Server does not cause any error. Browser,from where I am calling the Nodejs server, does not show any error.

Any insight is appreciated.

After Arif pointed out that this can be solved by Apache settings, I am adding the Virtualhost seetings at

/etc/apache2/sites-enabled/000-default.conf

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName www.example.com

        Redirect permanent / https://www.example.com

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

<VirtualHost *:443>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/mysite
        Servername www.example.com

        SSLEngine on
        SSLCertificateKeyFile /path/to/sslkey.key
        SSLCertificateFile /path/to/certificate.crt
        SSLCertificateChainFile /path/to/cabundle.ca-bundle


        <Directory /var/www/html/mysite>
                AllowOverride All
                Options FollowSymlinks
        </Directory>
</Virtualhost>

The client side requests are sent to https://www.example.com:8443

2
You must use https to make request that is https://www.example.com:8443. If you are requesting https://www.example.com:8443 then there is no role of apache. - Arif Khan
Can you make request to nodejs server in EC2 (curl -Ik https://127.0.0.1:8443) ? Did you add any rules in iptables before? - ronald8192
@ArifKhan Sorry, my bad. It is https://... - user7314977
@ronald8192 I got the following : HTTP/1.1 404 Not Found X-Powered-By: Express Content-Security-Policy: default-src 'self' X-Content-Type-Options: nosniff Content-Type: text/html; charset=utf-8 Content-Length: 140 Date: Sat, 21 Oct 2017 23:13:59 GMT Connection: keep-alive........................No, I never did that. - user7314977
@Sam11 if you are getting not found that means you are not implemented / GET route - Arif Khan

2 Answers

0
votes

First of all you need to enable ssl and reverse proxy apache module by following command

sudo a2enmod ssl
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer
sudo a2enmod lbmethod_byrequests

and then update apache ssl config(/etc/apache2/sites-available/default-ssl.conf) file bellow

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
        ServerAdmin [email protected]
        ServerName your_domain.com
        ServerAlias www.your_domain.com
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        SSLEngine on
        SSLCertificateFile /path/to/certificate.crt
        SSLCertificateKeyFile /path/to/sslkey.key
        ProxyRequests Off
        ProxyPreserveHost On
        ProxyVia Full
        <Proxy *>
          Require all granted
        </Proxy>
        <Location />
          ProxyPass http://localhost:8443
          ProxyPassReverse http://localhost:8443
       </Location>
    </VirtualHost>
</IfModule>

now add ssl file and restart apache

sudo a2ensite default-ssl.conf
sudo service apache2 restart

Now it should work fine https://your_domain.com

Note: You must open http and https port from AWS console in security group

0
votes

Sorry for delayed reply. The problem was the CSP settings which were not allowing HTTPS and WSS traffic.

Also, we needed to add

({secure: true})

while creating the client side Socket using socket.io. Now it is working fine. Thank you all for the inputs.