tech_memo / nginx


tech_memo

性能チューニング

  • worker_rlimit_nofile
    • nginx workerプロセス当たりのファイルディスクリプタ(open files)上限数
      • nginx workerプロセスのulimit関連の数値は下記にて確認できる
        $ cat /proc/`ps ax | grep nginx | grep worker | head -n1 | awk '{print $1}'`/limits
        Limit                     Soft Limit           Hard Limit           Units
        Max cpu time              unlimited            unlimited            seconds
        Max file size             unlimited            unlimited            bytes
        Max data size             unlimited            unlimited            bytes
        Max stack size            8388608              unlimited            bytes
        Max core file size        0                    unlimited            bytes
        Max resident set          unlimited            unlimited            bytes
        Max processes             63707                63707                processes
        Max open files            4096                 4096                 files
        Max locked memory         65536                65536                bytes
        Max address space         unlimited            unlimited            bytes
        Max file locks            unlimited            unlimited            locks
        Max pending signals       63707                63707                signals
        Max msgqueue size         819200               819200               bytes
        Max nice priority         0                    0
        Max realtime priority     0                    0
        Max realtime timeout      unlimited            unlimited            us

HOMEディレクトリを公開

  • /etc/nginx/conf.dに下記を作成してサービスをリロード
    server {
       listen 80;
       server_name MY_WEB_SERVER;
       charset utf8;
       index index.php;
       client_max_body_size 128M;
    
       location /my_pulibc {  # ★ http://MY_WEB_SERVER/の後に続く文字列を設定
           alias /var/www/html/my_home_dir;  # ★ /home/my_home_dir のsymbolicリンクを/var/www/htmlに作成している前提
       }
    
       error_page   500 502 503 504  /error.html;
       location = /error.html {
               root /usr/share/nginx/html;
       }
    }

ファイル一覧(Index of)を表示させる

  • デフォルトだとディレクトリ指定のURLアクセスはエラーになる
  • ディレクトリインデックスを設定するとディレクトリ指定のURLアクセスで、ファイル一覧が表示されるようになる
    # nginx.confに下記追加
    autoindex on;
    autoindex_exact_size off;
    autoindex_localtime on;
    • 追記箇所はserver{}でもlocation{}でもhttp{}等で可

ファイル拡張子とMIMEタイプの変更・追加

  • /etc/nginx/mime.types で定期されているので、下記を編集して、systemctl reload nginx.serviceを実行する
    types {
       text/html                             html htm shtml;
       text/css                              css;
       text/xml                              xml;
       image/gif                             gif;
       image/jpeg                            jpeg jpg;
       application/javascript                js;
       application/atom+xml                  atom;
       application/rss+xml                   rss;
    
       text/mathml                           mml;
       text/plain                            txt;
       ...
  • 例) *.logをDLじゃなくて、ブラウザ上でみたい場合は下記の用に追加
       text/plain                            txt log;

最新の20件

2023-01-26 2022-11-11 2022-03-02 2022-02-03 2021-11-18 2021-11-11 2021-10-27
  • tech_memo/nginx
2021-10-04 2021-09-30 2021-08-24 2021-04-01 2021-02-25 2020-08-13 2020-05-22 2020-04-16 2020-04-15 2020-03-23 2020-03-12 2020-02-27

今日の1件

  • tech_memo/nginx(1)

  • counter: 373
  • today: 1
  • yesterday: 0
  • online: 1