Nginxのコードをなんとなく理解する

Nginxの特徴→リバースプロシキ: webサーバーの分身になって、処理をこなう。処理が大きくなってきたら、新たな身代わりサーバを作成して、負荷を分散してくれる。

理解するコードはこれ。(深くは追わない)

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # 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;

    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 {
        }
    }
}

各コードを見ていく

#ps aux |grep nginx |grep -v grepで起動確認時に表示されるユーザ名
user nginx;
#nginxは、複数のワーカープロセスを、一つのマスタープロセスで制御する仕組み。
#autoにすれば自動で設定してくれる。
worker_processes auto;
error_log /var/log/nginx/error.log;
#PID:プロセスに割り振られた識別番号つまりプロセスID
#プロセスについて詳しく→(https://eng-entrance.com/linux-process)
pid /run/nginx.pid;
events {
    #1つのworkerプロセスに対する同時接続数の最大値を指定します。
    #nginx全体の接続数
    worker_connections 1024;
}
http {
    #ログファイルの書式を指定。これはmainという書式
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

  #アクセスログのパスと、その書式を指定(main。上に定義されてあるmain。)
    access_log  /var/log/nginx/access.log  main;

    #高速化のためのオプションで、非常に内部的なもの。今回は深くまで追わないことにする。
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
   #HTTP接続する時間を指定。繋ぎすぎは、負荷かかる
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # 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でconf.dディレクトリ以下のものを読み込むようになっています。
  #設定ファイルを分けて管理するため。
    include /etc/nginx/conf.d/*.conf;
 server {
        #listenは、使用するIPアドレス、ポートを指定する
        listen       80 default_server;#ポート番号80
        listen       [::]:80 default_server;
        server_name  _;
        #ドキュメントルートを指定。webサーバの最上部のdir
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        #最後にincludeでconf.dディレクトリ以下のものを読み込むようになっています。
       #設定ファイルを分けて管理するため。
        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 {
        }
    }

参考 nginxの基本的なコマンド

https://qiita.com/Naggi-Goishi/items/effa3afdfdba9fbbaa50

https://www.atmarkit.co.jp/ait/articles/1407/24/news003_4.html

nginxの設定ファイル nginx.conf の読み方 超入門

worker~系

nginx - 基本ディレクティブ(worker)

Nginx 入門

nginxの基本設定を改めてちゃんと調べてみた - Qiita

Nginxのインストールと基本設定

3.1 Nginxの基本構文

nginx 初期構成

【技術書要約】nginx実践入門のポイントを3分で押さえる - 初心者インフラエンジニアが困ったときに試行錯誤するブログ

Nginx 実践入門 ー詳しい語句説明とともに - Qiita