Question

Express NodeJS App on Ubuntu Droplet

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>;?

Subscribe
Share

Submit an 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