Table of Contents

Nginx

About

nginx is a web server

Concept

Process

nginx has one master process and several worker processes. The main purpose of the master process is to read and evaluate configuration, and maintain worker processes. Worker processes do actual processing of requests.

The nginx.pid file that holds the process id is written in the directory:

List the process:

ps -ax | grep nginx
16015 ?        Ss     0:00 nginx: master process /usr/sbin/nginx
16016 ?        S      0:00 nginx: worker process

HTTP request processing

See Nginx - HTTP Request Processing

Default block

The web content is served from a root directory which is by default /var/www/html but you may control your configuration file to find it (below is the location at /usr/share/nginx/html

server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
        location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }

Directory Structure

Server Logs

Configuration file

Default

All conf file placed into include /etc/nginx/conf.d/*.conf are automatically loaded thanks to this line in nginx.conf

http {
    ....
    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
}

Debian

Only for Debian, the default nginx.conf file has the following conf

http {
    ....
    include /etc/nginx/sites-enabled/*;
}

They use then the following structure:

Reverse Proxy / Load balancer

HTTP - Gateway (Reverse Proxy) - Network - Load Balancer (NLB, ALB, CLB)

Installation

Doc

sudo apt-get install nginx 
sudo yum update -y
sudo yum install nginx -y

Verification that Nginx is up

curl -I 127.0.0.1
HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Wed, 01 Jan 2020 10:26:06 GMT
Content-Type: text/html
Content-Length: 4833
Last-Modified: Fri, 16 May 2014 15:12:48 GMT
Connection: keep-alive
ETag: "53762af0-12e1"
Accept-Ranges: bytes

Protection

Dokuwiki

https://www.nginx.com/resources/wiki/start/topics/recipes/dokuwiki/

Documentation / Reference