Basic Server Block in Nginx

From the Nginx cheat sheet ยท Server Blocks & Virtual Hosts ยท verified Jul 2026

Basic Server Block

Setting up a basic server block

nginx
server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/example.com;
    index index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
}
๐ŸŒ Server blocks host multiple sites on one server
๐Ÿ“ Each block needs unique server_name
๐Ÿ”— Symlink from sites-available to sites-enabled
โšก try_files directive for efficient file serving

More Nginx tasks

Back to the full Nginx cheat sheet