Report this

What is the reason for this report?

Express NodeJS App on Ubuntu Droplet

Posted on May 21, 2019

Hi,

I have followed the below tutorials to get set up with an Ubuntu 16.04 server running NodeJS, NGINX, and with SSL set up via Let’s Encrypt: https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-16-04 https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04 https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04 https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-16-04

All works pretty well in that my own domain now points to my droplet and I can connect under SSL and get to the NGINX Welcome page.

However I have deployed my express app to /home/stuart/<project-name> but I cannot access its home route (‘/’). Locally the app runs at port 3000

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

In NGINX my sites-available/defaults has a server block

 root /var/www/html;

       # Add index.php to the list if you are using PHP
       index index.html index.htm index.nginx-debian.html;

       server_name <mydomain> www.<mydomain>; //the actual file has my domain name in

       location / {
               # First attempt to serve request as file, then
               # as directory, then fall back to displaying a 404.
               try_files $uri $uri/ =404;
       }

My sites-enabled/defaults has a server block

root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name <mydomain> www.<mydomain>;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

Do I need to just clone my express app into /var/www/html and modify the defaults in sites-available and sites-enabled to root /var/www/html/<appname>;?



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.

ok solved this. Just had to add

proxy_pass http://127.0.0.1:3000;

in the location object of the server block

This comment has been deleted

i used npx express-generator to bootstrap my Express app and can’t figure out how to get it to work on my droplet! 😡

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.