linux:nginx

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

次のリビジョン
前のリビジョン
linux:nginx [2020/04/19 07:33] – 作成 ともやんlinux:nginx [2023/09/12 10:55] (現在) – [Events モジュールの設定] ともやん
行 1: 行 1:
-====== NGINX - High Performance Load Balancer, Web Server, & Reverse Proxy ======+====== NGINX - ハイパフォーマンス ロードバランサー、Webサーバー、リバースプロキシ ====== 
 +<WRAP #logo> 
 +{{linux:nginx-logo.svg?200|NGINX Logo}} 
 +</WRAP> 
 +本家: [[https://www.nginx.com/|NGINX | High Performance Load Balancer, Web Server, & Reverse Proxy]]\\ 
 +ソースコード: [[http://hg.nginx.org/nginx/|nginx: Mercurial repository]]\\ 
 + 
 +===== インストール ===== 
 +<code> 
 +$ sudo dnf install nginx 
 +</code> 
 +<WRAP prewrap 100% #result_long> 
 +<code> 
 +whitewaterfoundry_wslu                                                        212  B/s | 833  B     00:03 
 +依存関係が解決しました。 
 +========================================================================================================== 
 + Package                     Architecture       Version                        Repository            Size 
 +========================================================================================================== 
 +インストール: 
 + nginx                       x86_64             1:1.16.1-1.fc31                fedora               564 k 
 +依存関係のインストール: 
 + gperftools-libs             x86_64             2.7-6.fc31                     fedora               322 k 
 + nginx-mimetypes             noarch             2.1.48-6.fc31                  fedora                19 k 
 + 
 +トランザクションの概要 
 +========================================================================================================== 
 +インストール  3 パッケージ 
 + 
 +ダウンロードサイズの合計: 905 k 
 +インストール済みのサイズ: 3.5 M 
 +これでよろしいですか? [y/N]: y 
 +パッケージのダウンロード: 
 +(1/3): nginx-mimetypes-2.1.48-6.fc31.noarch.rpm                                69 kB/s |  19 kB     00:00 
 +(2/3): gperftools-libs-2.7-6.fc31.x86_64.rpm                                  586 kB/s | 322 kB     00:00 
 +(3/3): nginx-1.16.1-1.fc31.x86_64.rpm                                         802 kB/s | 564 kB     00:00 
 +---------------------------------------------------------------------------------------------------------- 
 +合計                                                                          575 kB/s | 905 kB     00:01 
 +トランザクションの確認を実行中 
 +トランザクションの確認に成功しました。 
 +トランザクションのテストを実行中 
 +トランザクションのテストに成功しました。 
 +トランザクションを実行中 
 +  準備             :                                                                                  1/1 
 +  インストール中   : nginx-mimetypes-2.1.48-6.fc31.noarch                                              1/3 
 +  インストール中   : gperftools-libs-2.7-6.fc31.x86_64                                                 2/3 
 +  インストール中   : nginx-1:1.16.1-1.fc31.x86_64                                                      3/3 
 +  scriptletの実行中: nginx-1:1.16.1-1.fc31.x86_64                                                      3/3 
 +  検証             : gperftools-libs-2.7-6.fc31.x86_64                                                 1/3 
 +  検証             : nginx-1:1.16.1-1.fc31.x86_64                                                      2/3 
 +  検証             : nginx-mimetypes-2.1.48-6.fc31.noarch                                              3/3 
 + 
 +インストール済み: 
 +  gperftools-libs-2.7-6.fc31.x86_64  nginx-1:1.16.1-1.fc31.x86_64  nginx-mimetypes-2.1.48-6.fc31.noarch 
 +</code> 
 +</WRAP> 
 + 
 +===== NGINX の設定 ===== 
 + 
 +==== 自動起動設定 ==== 
 +<code> 
 +$ sudo systemctl enable nginx 
 +</code> 
 +<WRAP prewrap 100% #result> 
 +<code> 
 +Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service. 
 +</code> 
 +</WRAP> 
 + 
 +==== 設定ファイルのバックアップ ==== 
 +<code> 
 +$ sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.org 
 +</code> 
 +<WRAP prewrap 100% #result> 
 +<code> 
 +Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service. 
 +</code> 
 +</WRAP> 
 + 
 +==== ワーカープロセス数の設定 ==== 
 +サーバーのプロセッサ数を調べる。\\ 
 +※下記の例では 4 個のプロセッサを搭載している。\\ 
 +<code> 
 +$ cat /proc/cpuinfo | grep processor 
 +</code> 
 +<WRAP prewrap 100% #result> 
 +<code> 
 +processor       : 0 
 +processor       : 1 
 +processor       : 2 
 +processor       : 3 
 +</code> 
 +</WRAP> 
 + 
 +ワーカープロセス数を **auto** または、プロセッサ数に設定。\\ 
 +<code> 
 +$ sudo vi /etc/nginx/nginx.conf 
 +</code> 
 +<WRAP prewrap 100% #mincode> 
 +<code autoconf /etc/nginx/nginx.conf> 
 +#worker_processes auto; 
 +worker_processes  4; 
 +</code> 
 +</WRAP> 
 +**auto** の場合はコア数を見て自動設定される。\\ 
 + 
 +==== その他ワーカープロセスの設定 ==== 
 +<WRAP prewrap 100% #mincode> 
 +<code autoconf /etc/nginx/nginx.conf> 
 +#worker_processes auto; 
 +worker_processes 4; 
 +worker_rlimit_nofile 8192;               # ワーカープロセスが扱える最大ファイル数 
 +worker_priority 0;                       # ワーカープロセスの優先度 
 +worker_cpu_affinity 0001 0010 0100 1000; # ワーカープロセスが使うCPUコア(4コア) 
 +</code> 
 +</WRAP> 
 + 
 +※**worker_cpu_affinity** はプロセッサの数に応じて変更する。\\ 
 +<WRAP prewrap 100% #mincode> 
 +<code autoconf /etc/nginx/nginx.conf> 
 +worker_cpu_affinity 01 10;                         # CPU 2コア 
 +worker_cpu_affinity 001 010 100;                   # CPU 3コア 
 +worker_cpu_affinity 0001 0010 0100 1000;           # CPU 4コア 
 +worker_cpu_affinity 00001 00010 00100 01000 10000; # CPU 5コア 
 +</code> 
 +</WRAP> 
 + 
 +==== Events モジュールの設定 ==== 
 +<WRAP prewrap 100% #mincode> 
 +<code autoconf /etc/nginx/nginx.conf> 
 +events { 
 +    multi_accept off;        # リスニングソケットオープン時の相互排他制御 
 +    worker_connections 1024; # ワーカープロセス同時接続数 
 +    use epoll;               # Linux 3.10 系で効率的なモデル 
 +
 +</code> 
 +</WRAP> 
 + 
 +==== セッション、セキュリティ設定 ==== 
 +<WRAP prewrap 100% #mincode> 
 +<code autoconf /etc/nginx/nginx.conf> 
 +http { 
 +    server_tokens off;       # バージョン情報非表示 
 +    #keepalive_timeout  65; 
 +    keepalive_requests 1000; # KeepAlive 接続で処理できる最大要求数 
 +    keepalive_timeout     5; # 要求が終わって KeepAlive 接続を切るまでの秒数 
 +
 +</code> 
 +</WRAP> 
 + 
 +==== タイプハッシュテーブルの最大値を設定 ==== 
 +<WRAP prewrap 100% #mincode> 
 +<code autoconf /etc/nginx/nginx.conf> 
 +http { 
 +    #types_hash_max_size 2048; 
 +    types_hash_max_size 4096; 
 +
 +</code> 
 +</WRAP> 
 + 
 +==== アップロードサイズ制限の変更 ==== 
 +ファイルのアップロード時に **413 Request Entity Too Large** が発生する場合は、デフォルト 1M の制限を変更する。\\ 
 +<WRAP prewrap 100% #mincode> 
 +<code autoconf /etc/nginx/nginx.conf> 
 +http { 
 +    #client_max_body_size 1m; # default 
 +    client_max_body_size 100m; 
 +
 +</code> 
 +</WRAP> 
 + 
 +==== 設定の反映 ==== 
 +設定ファイルの内容を検証する。\\ 
 +<code> 
 +$ sudo nginx -t 
 +</code> 
 +<WRAP prewrap 100% #result> 
 +<code> 
 +nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 
 +nginx: configuration file /etc/nginx/nginx.conf test is successful 
 +</code> 
 +</WRAP> 
 + 
 +nginx を再起動する。\\ 
 +<code> 
 +$ sudo systemctl restart nginx 
 +</code> 
 + 
 +===== 動作確認 ===== 
 +[[http://localhost|]] にアクセスする。\\ 
 +{{:linux:nginx_install_001.png?800|NGINX インストール 001}}\\ 
 + 
 +===== トラブルシューティング ===== 
 + 
 +==== 設定ファイルの内容検証で警告が発生する ==== 
 +<code> 
 +nginx: [warn] could not build optimal types_hash, you should increase either types_hash_max_size: 2048 or types_hash_bucket_size: 64; ignoring types_hash_bucket_size 
 +</code> 
 + 
 +タイプハッシュテーブルの最大値を変更する。\\ 
 +<WRAP prewrap 100% #mincode> 
 +<code autoconf /etc/nginx/nginx.conf> 
 +http { 
 +    #types_hash_max_size 2048; 
 +    types_hash_max_size 4096; 
 +
 +</code> 
 +</WRAP> 
 +/etc/nginx/mime.types に含まれる多数のタイプに対して 2048 では不十分のようである。\\ 
 +[[https://bugzilla.redhat.com/show_bug.cgi?id=1564878|1564878 – NGINX: could not build optimal types_hash, you should increase either types_hash_max_size]]\\ 
 + 
 +====参考文献 ===== 
 +[[http://nginx.org/en/docs/http/ngx_http_core_module.html|Module ngx_http_core_module]]\\ 
 +[[https://www.nginx.com/resources/wiki/start/topics/tutorials/install/|Install | NGINX]]\\ 
 +[[http://shim0mura.hatenadiary.jp/entry/20120110/1326198429|入門! nginx - tumblr]]\\ 
 +[[https://blog.dksg.jp/2012/04/centosnginx-php-fpminstallwordpress.html|CentOSにNginx + php-fpmをInstall、設定してWordPressを動かす]]\\
  
  • linux/nginx.1587249193.txt.gz
  • 最終更新: 2020/04/19 07:33
  • by ともやん