Question
How to run node.js server with Nginx
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:
Welcome to nginx!
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
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.
×