How to Install Nginx on Linux: Server Blocks, Static Sites and proxy_pass Basics

install nginx linux - custom-nginxinst-featured.png

Install Nginx on Linux is the starting point for millions of LEMP stacks, Kubernetes ingress nodes, and static marketing sites. Nginx uses an event-driven worker model and keeps configuration in clear server blocks.

For TLS termination, upstream apps, and production tuning, continue with our
Nginx reverse proxy guide and
502 troubleshooting.

Why Nginx

Low memory footprint, strong static file performance, and a standard choice as a reverse proxy in front of Node, PHP-FPM, or Gunicorn.

Nginx role
edge server

Install the Package

Ubuntu uses nginx; AlmaLinux uses nginx from AppStream or EPEL depending on image.

bashUbuntu
sudo apt install -y nginx
sudo systemctl enable --now nginx
curl -sI http://127.0.0.1/ | head -3
package install
enable service

Configuration Layout

Global settings in nginx.conf; per-site files in sites-available (Debian) or conf.d/*.conf (RHEL).

config paths
includes

Your First server Block

Define listen, server_name, root, and index for a hostname.

nginxminimal vhost
server {
    listen 80;
    server_name site.example;
    root /var/www/site.example/html;
    index index.html;
}
server {}
DocumentRoot

Test and Reload

Never skip nginx -t — a syntax error on reload can leave you fixing from console.

bashapply
sudo nginx -t
sudo systemctl reload nginx
nginx -t
reload

Serve a Static Site

Drop index.html in the root; optional gzip and cache headers for assets.

bashcreate site
sudo mkdir -p /var/www/site.example/html
echo '<h1>Hello Nginx</h1>' | sudo tee /var/www/site.example/html/index.html
static files
index.html

Intro to reverse proxy

Pass traffic to an app on localhost — the pattern behind WordPress PHP-FPM and APIs.

nginxproxy example
location /app/ {
    proxy_pass http://127.0.0.1:3000/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
}
proxy_pass
upstream

Access and Error Logs

Default paths under /var/log/nginx/ — essential for debugging 4xx/5xx.

bashwatch errors
sudo tail -f /var/log/nginx/error.log
logs
tail -f

Firewall and Next Steps

Open 80/443, then add Certbot. Tune worker_connections only after you measure real traffic.

bashufw
sudo ufw allow 'Nginx Full'
UFW + TLS
checklist

Quick Reference

  • nginx -t before every reload
  • Debian: symlink from sites-available to sites-enabled
  • Production proxy/TLS: see our reverse proxy guide

Related tutorials

Diagrams are original illustrations by Gnome IT Solutions. Tutorial text © Gnome IT Solutions.