NGINX

Back to Production-Engineering/NGINX

General purpose web server. Uses asynchronous event-driven approach to handling requests. Can handle high volumes of connections, with low memory footprint.

Nginx is often set up as a reverse proxy solution, scaling infrastructures or passing requests to other servers not designed to handle large client loads.

Proxying

Nginx is designed to handle many concurrent connections.

Proxying is accomplished by passing requests to other servers for actual processing, which relays back through Nginx to the client.

Basics

Example:

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

    location /images/ {
        root /data;
    }
  }
}

Block Selection

Nginx uses blocks to build hierarchical configuration structure.

server blocks

Nginx determines which server block to use with listen and server_name

location blocks

location directives look like: location <optional_modifier> <location_match> {}

how Nginx chooses location block

Nginx evaluates the possible location contexts by comparing the request URI to each of the locations.

source

General (Common Mistakes)

source

defaults