Six Reminders For Deploying Your Web App With Nginx
Publish Date - 5th July 2021
Last Updated - 17th July 2021
90% of the applications I deploy are on Ubuntu servers.
Whether it's a Next.js app, Node.js server or a Common Lisp app, I use Nginx and the process is almost identical. However, setting up a new app on a new server is not something I do every day. It's easy to forget minor details that have big impacts.
Below is a list of reminders that, if not remembered, will cause the web app to fail.
If you are ever found asking "why isn't this nginx site loading?", it's one of these six.
1. Use the root section in Nginx properly
Your web files do not need to be in /var/www
. Where ever you decide to put your HTML/JS/CSS, make sure the root section inside the Nginx server block points there:
root: /dir/of/public/folder
2. If your site does load with nginx, it's most likely your firewall
9 times out of 10, I do everything right with server setup. But I still get that (blasted) 503 error.
Use command utf status
in the command line.
Check to see if your firewall has Nginx HTTP
and port 80
.
3. Always reset nginx after changing a config file
Behind the scenes there are many things that can effect your Nginx configuration.
When you make major changes to any config files, get in the habit of restarting nginx.
Run: sudo systemctl restart nginx
4. Server names help for multiple sites on the same server
Sometimes, you want to have more than one website on the same server.
For that, a simple system name which points to the domain name will allow multiple domains to live behind port 80 or 443.
In the server block of the Nginx file, add:
server { server_name yourWebsite.com www.yourWebsite.com; ... < --- other stuff in config }
5. Certbot for free ssl
Remember to get ssl setup for your website
run the nginx setup wizard: sudo certbot --nginx
6. Allow ssl port in your firewall
Secure website access (ssl) is under a different port. After installing Cerbot, you will need to allow port 443/tcp
in your firewall.
run: sudo ufw allow 443