Nginx - Server Block Definition

About

A server block is a block that define a web server endpoints.

It maps an URI to:

and set some configurations.

It is the equivalent of a Virtual host for apache.

By default, Nginx has one server block enabled by default.

Syntax

A server block is inside a http block.

http {
    server {
    }
}

and contains one or more location blocks.

server {
    location / {
        root /data/www;
    }

    location /images/ {
        root /data;
    }
}

Default

The default server is a property of the listen port.

Process:

  • If there is a default server in the listen directive, the server is default one
server {
    listen      80 default_server;
    server_name example.net www.example.net;
    ...
}
  • otherwise, the first server block is chosen

Example

Documentation / Reference


Powered by ComboStrap