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

May 9, 2018 2k views
Nginx Node.js Security Let'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.end("hello world\n");

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

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?

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!