linux:nginx

差分

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

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
linux:nginx [2020/04/19 08:18] ともやんlinux:nginx [2023/09/12 10:55] (現在) – [Events モジュールの設定] ともやん
行 1: 行 1:
-<html> 
-  <style> 
-    #result pre, #mincode pre { 
-      overflow: scroll; 
-      overflow-x: hidden; 
-      font-size: 10px; 
-    } 
-    #result_long pre { 
-      height: 400px; 
-      overflow: scroll; 
-      overflow-x: hidden; 
-      font-size: 10px; 
-    } 
-    #logo { 
-      background-color: #222; 
-      width: fit-content; 
-      padding: 10px; 
-    } 
-    #logo p { 
-      margin: 0; 
-    } 
-  </style> 
-</html> 
 ====== NGINX - ハイパフォーマンス ロードバランサー、Webサーバー、リバースプロキシ ====== ====== NGINX - ハイパフォーマンス ロードバランサー、Webサーバー、リバースプロキシ ======
 <WRAP #logo> <WRAP #logo>
行 35: 行 12:
 <WRAP prewrap 100% #result_long> <WRAP prewrap 100% #result_long>
 <code> <code>
-whitewaterfoundry_wslu                                                                  212  B/s | 833  B     00:03+whitewaterfoundry_wslu                                                        212  B/s | 833  B     00:03
 依存関係が解決しました。 依存関係が解決しました。
-======================================================================================================================== +========================================================================================================== 
- Package                         Architecture           Version                            Repository              Size + Package                     Architecture       Version                        Repository            Size 
-========================================================================================================================+==========================================================================================================
 インストール: インストール:
- nginx                           x86_64                 1:1.16.1-1.fc31                    fedora                 564 k+ nginx                       x86_64             1:1.16.1-1.fc31                fedora               564 k
 依存関係のインストール: 依存関係のインストール:
- gperftools-libs                 x86_64                 2.7-6.fc31                         fedora                 322 k + gperftools-libs             x86_64             2.7-6.fc31                     fedora               322 k 
- nginx-mimetypes                 noarch                 2.1.48-6.fc31                      fedora                  19 k+ nginx-mimetypes             noarch             2.1.48-6.fc31                  fedora                19 k
  
 トランザクションの概要 トランザクションの概要
-========================================================================================================================+==========================================================================================================
 インストール  3 パッケージ インストール  3 パッケージ
  
行 54: 行 31:
 これでよろしいですか? [y/N]: y これでよろしいですか? [y/N]: y
 パッケージのダウンロード: パッケージのダウンロード:
-(1/3): nginx-mimetypes-2.1.48-6.fc31.noarch.rpm                                          69 kB/s |  19 kB     00:00 +(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 +(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 +(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+合計                                                                          575 kB/s | 905 kB     00:01
 トランザクションの確認を実行中 トランザクションの確認を実行中
 トランザクションの確認に成功しました。 トランザクションの確認に成功しました。
行 64: 行 41:
 トランザクションのテストに成功しました。 トランザクションのテストに成功しました。
 トランザクションを実行中 トランザクションを実行中
-  準備             :                                                                                                1/1 +  準備             :                                                                                  1/1 
-  インストール中   : nginx-mimetypes-2.1.48-6.fc31.noarch                                                           1/3 +  インストール中   : nginx-mimetypes-2.1.48-6.fc31.noarch                                              1/3 
-  インストール中   : gperftools-libs-2.7-6.fc31.x86_64                                                              2/3 +  インストール中   : gperftools-libs-2.7-6.fc31.x86_64                                                 2/3 
-  インストール中   : nginx-1:1.16.1-1.fc31.x86_64                                                                   3/3 +  インストール中   : nginx-1:1.16.1-1.fc31.x86_64                                                      3/3 
-  scriptletの実行中: 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 +  検証             : gperftools-libs-2.7-6.fc31.x86_64                                                 1/3 
-  検証             : nginx-1:1.16.1-1.fc31.x86_64                                                                   2/3 +  検証             : nginx-1:1.16.1-1.fc31.x86_64                                                      2/3 
-  検証             : nginx-mimetypes-2.1.48-6.fc31.noarch                                                           3/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+  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> </code>
 </WRAP> </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.1587251886.txt.gz
  • 最終更新: 2020/04/19 08:18
  • by ともやん