# Nginx Server Block

> The Nginx settings block for one site: its port, its names and its folder.

**Field:** Infrastructure  
**Category:** Web Serving & Nginx  
**Also known as:** Server Block, Nginx server Directive

## Think of it like

It is like one drawer in a big desk. Each drawer holds the papers for one site.

## Definition

A server block is how Nginx writes a virtual host. It is a group of settings inside server { } in the config. The listen line says which port it answers on. The server_name line says which site names it is for. Inside, root points at the site's folder, and location blocks set rules for parts of the site.

## Example

Jack's server has two server blocks. One answers example.com on port 443. The other sends plain HTTP on port 80 over to HTTPS.

## Example code

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

One server block. It answers example.com on port 80 and serves files from one folder.

## Why it matters

Every site on an Nginx server is set up this way. Reading one is the first step in fixing one.

## Common mistake

Leaving out server_name, or spelling it wrong. Nginx then sends the request to its default block, and the wrong site shows.

## Three principles

- **One site.** Each block is one virtual host.
- **listen and server_name.** The port and the names it answers.
- **root.** The folder it serves from.

## Related terms

- [Virtual Host](https://learn.benibix.com/term/infrastructure/virtual-host)
- [Nginx](https://learn.benibix.com/term/infrastructure/nginx)
- [nginx.conf](https://learn.benibix.com/term/infrastructure/nginx-configuration-file)
- [Document Root](https://learn.benibix.com/term/infrastructure/document-root)
- [Network Port](https://learn.benibix.com/term/infrastructure/port)

![Two site names, example.com and shop.example, both point to one server with one IP address. Inside the server, nginx.conf holds two server blocks. Each block matches one name and points at its own folder of files.](https://learn.benibix.com/diagrams/inf2-virtual-hosts.svg)

---

Source: https://learn.benibix.com/term/infrastructure/nginx-server-block
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
