NGINX 동적 모듈 설치(ngx-pagespeed)

Yum 설치된 NGINX와 동일한 버전을 다운로드

  • 서버에 설치된 nginx 버전은 nginx/1.20.1
  • NGINX Download: nginx/1.20.1

ngx-pagespeed 다운로드

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

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

좋은 웹페이지 즐겨찾기