NGINXダイナミックモジュールのインストール(ngx-pagespeed)


YumがインストールしたNGINXと同じバージョンをダウンロード
  • サーバにインストールされているnginxバージョンはnginx/1.20.1
  • です.
  • NGINX Download: nginx/1.20.1
  • ngx-pagespeedダウンロード
  • ngx-pagespeed Download : pagespeed-v1.13.35.2-stable
  • 解凍nginx
    tar xvfz nginx-1.20.1.tar.gz
    nginxソースディレクトリからngx-pagespeedをダウンロードおよび解凍
    cd nginx-1.20.1
    wget https://github.com/apache/incubator-pagespeed-ngx/archive/refs/tags/latest-stable.tar.gz
    tar xvfz latest-stable.tar.gz
    nginxソースディレクトリにngx-pagespeedをインストール(エラー)
    ./configure --with-compat --add-dynamic-module=./incubator-pagespeed-ngx-latest-stable/
    ...(생략)
    adding module in ./incubator-pagespeed-ngx-latest-stable
    ngx_pagespeed: pagespeed optimization library not found:
    
      You need to separately download the pagespeed library:
         $ cd ./incubator-pagespeed-ngx-latest-stable
         $ wget https://dl.google.com/dl/page-speed/psol/1.13.35.2-x64.tar.gz
         $ tar -xzvf 1.13.35.2-x64.tar.gz # expands to psol/
    pagespeedライブラリのダウンロード
    cd ./incubator-pagespeed-ngx-latest-stable
    wget https://dl.google.com/dl/page-speed/psol/1.13.35.2-x64.tar.gz
    tar -xzvf 1.13.35.2-x64.tar.gz
    nginx lib構築
    cd nginx-1.20.1
    yum install libuuid-devel pcre pcre-devel zlib zlib-devel
    ngx-pagespeed再構築
    ./configure --with-compat --add-dynamic-module=./incubator-pagespeed-ngx-latest-stable/
    make modules
    ngx-pagespeedモジュールの確認
    # pwd
    /root/nginx-1.20.1
    # ls
    CHANGES  CHANGES.ru  LICENSE  Makefile  README  auto  conf  configure  contrib  html  incubator-pagespeed-ngx-latest-stable  latest-stable.tar.gz  man  objs  src
    # cd objs
    # ls -l ngx_pagespeed.so
    -rwxr-xr-x. 1 root root 20155616  1월 30 19:01 ngx_pagespeed.so
    ngx-pagespeedモジュールレプリケーション
    # 모듈 복사
    cp /root/nginx-1.20.1/objs/ngx_pagespeed.so /usr/share/nginx/modules/
    nginx設定ファイルの編集
    vi /etc/nginx/nginx.conf
    load_module modules/ngx_pagespeed.so;
    user nginx;
    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /run/nginx.pid;
    ...(생략)
    page-speed設定
    ...(생략)
     server {
            listen       80;
            listen       [::]:80;
            server_name  _;
            root         /usr/share/nginx/html;
            ...(생략)
           # pagespped 설정
           pagespeed on;
           pagespeed FileCachePath /var/ngx_pagespeed_cache;
           pagespeed EnableFilters defer_javascript;
           pagespeed EnableFilters insert_dns_prefetch;
    
           # Ensure requests for pagespeed optimized resources go to the pagespeed handler
           # and no extraneous headers get set.
           location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
                 add_header " " " ";
           }
           location ~ "^/pagespeed_static/" { }
           location ~ "^/ngx_pagespeed_beacon$" { }
     }
    nginxプロファイルの確認
    nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    nginxを再起動
    systemctl restart nginx