Hi all,
I’m trying to figure out how to get my Node server.js to run on my droplet with Let’s Encrypt / nginx
It was working by just ssh-ing into the droplet, cd into the project folder (cloned from Github repo) and running ‘forever start server.js’.
But then I ran though this tutorial (https://www.youtube.com/watch?v=m9aa7xqX67c) to install a Let’s Encrypt cert and now it only shows:
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
I can start or kill that default nginx menu, but now I’m not able to cd into the project folder and run forever start. I looked through many articles on what may work or not but I can’t figure anything out for the life of me. Definitely new to all the server / nginx stuff.
My /etc/nginx/sites-available/default looks like this:
server {
listen 80;
server_name mydomain.com www.mydomain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name mydomain.com www.mydomain.com;
ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
...
}
I tired setting a proxy as I saw in another forum to the location, and setting my node server.js to listen on that port, but that didn’t work either. It seems as if it’s either going straight to the nginx window or to ‘site cannot be reached’ if nginx is stopped.
location / {
proxy_pass http://127.0.0.1:3010/;
try_files $uri $uri/ =404;
}
Any thoughts are appreciated! Keith
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
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.
Hmmm all that sounds like it should work…
Just to be clear, this is what your nginx config should look like:
and make sure your server.js node app is running on port 3010.
i.e.: in express.js…
Then confirm nginx is running with
sudo service nginx status
and confirm your node app is running withforever list
or check the forever logs withforever logs server.js
More reference on running node.js in reverse proxy with nginx here: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04
Hello,
In addition to what has already been mentioned, I could also suggest taking a look at this quick video tutorial on how to deploy a Node.js App on Ubuntu with PM2, NGINX and Cloudflare:
Hope that this helps. Best, Bobby