What I Wanted to Do

I needed to serve a static site and set up a reverse proxy with nginx, but the config file syntax wasn’t obvious.

Basic Config File

server {
    listen 80;
    server_name example.com;

    root /var/www/html;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

Reverse Proxy Config

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

Test and Reload Config

nginx -t          # Syntax check
nginx -s reload   # Reload without downtime

Common Pitfalls

  • Always run nginx -t before reloading — a syntax error will take down the server
  • Missing semicolons ; are a frequent cause of errors
  • Before exposing nginx publicly, open ports 80 and 443 in the firewall

For firewall setup, see Linux UFW Firewall Basics.

Looking for reliable cloud infrastructure? Check out these developer-friendly services.