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

Show comments

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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

This comment has been deleted

ok solved this. Just had to add

proxy_pass http://127.0.0.1:3000;

in the location object of the server block