Question

LetsEncrypted Node.js HTTPS Server inaccessible from browser. Why it won't load?

Posted May 9, 2018 2.2k views
NginxNode.jsSecurityLet's Encrypt

I secured NGINX with SSL following this tutorial: https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04

I explicitly chose to redirect all requests to HTTPS.

Now, when visiting my webpage www.example.com, it correctly redirects me to https://www.example.com and shows the default NGINX text.

I want Express to run there, so I made this tiny script to test things out:

var https = require('https');
var fs = require('fs');

var options = {
  key: fs.readFileSync('/etc/letsencrypt/live/example.com/privkey.pem'),
  cert: fs.readFileSync('/etc/letsencrypt/live/example.com/cert.pem'),
  ca: fs.readFileSync('/etc/letsencrypt/live/example.com/chain.pem')
};

https.createServer(options, function (req, res) {
  res.writeHead(200);
  res.end("hello world\n");
}).listen(8000);

The page will not load at all. What am I doing wrong?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

It sounds like https is set up properly but Nginx is not configured to use your Express app for requests for the https site. Can you share the contents of your configuration files in /etc/nginx/sites-enabled?

Submit an Answer