Установка ngx_pagespeed для nginx centos 6
У нас уже был установлен nginx нужно добавить модуль ngx_pagespeed.

Нам нужно  получить текущие параметры конфигурации nignx


nginx -V


 

 

nginx version: nginx/1.8.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: —prefix=/etc/nginx —sbin-path=/usr/sbin/nginx —conf-path=/etc/nginx/nginx.conf —error-log-path=/var/log/nginx/error.log —http-log-path=/var/log/nginx/access.log —pid-path=/var/run/nginx.pid —lock-path=/var/run/nginx.lock —http-client-body-temp-path=/var/cache/nginx/client_temp —http-proxy-temp-path=/var/cache/nginx/proxy_temp —http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp —http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp —http-scgi-temp-path=/var/cache/nginx/scgi_temp —user=nginx —group=nginx —with-http_ssl_module —with-http_realip_module —with-http_addition_module —with-http_sub_module —with-http_dav_module —with-http_flv_module —with-http_mp4_module —with-http_gunzip_module —with-http_gzip_static_module —with-http_random_index_module —with-http_secure_link_module —with-http_stub_status_module —with-http_auth_request_module —with-mail —with-mail_ssl_module —with-file-aio —with-ipv6 —with-http_spdy_module —with-cc-opt=’-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector —param=ssp-buffer-size=4 -m64 -mtune=generic’


Нам понадобиться все что правее «configure arguments:» — сохраняем.

Ставим зависимости для билда


yum install gcc cmake unzip wget gcc-c++ pcre-devel zlib-devel -y


Качаем последниюю весрию nginx и распаковываем. Посмотреть последнюю можно тут


http://nginx.org/download/
cd
wget http://nginx.org/download/nginx-1.15.3.tar.gz
tar xzvf nginx-1.15.3.tar.gz


Смотрим PageSpeed Release Notes, https://www.modpagespeed.com/doc/release_notes,  я выбрал последнюю стабильную версию 1.13.35.2-stable и вставляем имя версии в переменную.
Дальше скачиваем pagespeed-ngx и psol


NPS_VERSION=1.13.35.2-stable
cd
wget https://github.com/apache/incubator-pagespeed-ngx/archive/v${NPS_VERSION}.zip
unzip v${NPS_VERSION}.zip
nps_dir=$(find . -name «*pagespeed-ngx-${NPS_VERSION}» -type d)
cd «$nps_dir»
NPS_RELEASE_NUMBER=${NPS_VERSION/beta/}
NPS_RELEASE_NUMBER=${NPS_VERSION/stable/}
psol_url=https://dl.google.com/dl/page-speed/psol/${NPS_RELEASE_NUMBER}.tar.gz
[ -e scripts/format_binary_url.sh ] && psol_url=$(scripts/format_binary_url.sh PSOL_BINARY_URL)
wget ${psol_url}
tar -xzvf $(basename ${psol_url})  # extracts to psol/


Компилируем нжинкс с модулем + старые параметры.


cd
cd nginx-1.15.3

./configure —add-module=$HOME/$nps_dir ${PS_NGX_EXTRA_FLAGS} —prefix=/etc/nginx —sbin-path=/usr/sbin/nginx —conf-path=/etc/nginx/nginx.conf —error-log-path=/var/log/nginx/error.log —http-log-path=/var/log/nginx/access.log —pid-path=/var/run/nginx.pid —lock-path=/var/run/nginx.lock —http-client-body-temp-path=/var/cache/nginx/client_temp —http-proxy-temp-path=/var/cache/nginx/proxy_temp —http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp —http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp —http-scgi-temp-path=/var/cache/nginx/scgi_temp —user=nginx —group=nginx —with-http_ssl_module —with-http_realip_module —with-http_addition_module —with-http_sub_module —with-http_dav_module —with-http_flv_module —with-http_mp4_module —with-http_gunzip_module —with-http_gzip_static_module —with-http_random_index_module —with-http_secure_link_module —with-http_stub_status_module —with-http_auth_request_module —with-mail —with-mail_ssl_module —with-file-aio —with-cc-opt=’-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector —param=ssp-buffer-size=4 -m64 -mtune=generic’


Если на этом этапе чего не хватает то нужно доустановить компоненты , к примеру yum install openssl-devel

если скомпилилось ок, компилируем и устанавливаем.


make
make install


естартим сервер


service nginx restart


проверяем модуль


nginx -V


nginx version: nginx/1.15.3
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: —add-module=/root/./incubator-pagespeed-ngx-1.13.35.2-stable —with-cc=/opt/rh/devtoolset-2/root/usr/bin/gcc —prefix=/etc/nginx —sbin-path=/usr/sbin/nginx —conf-path=/etc/nginx/nginx.conf —error-log-path=/var/log/nginx/error.log —http-log-path=/var/log/nginx/access.log —pid-path=/var/run/nginx.pid —lock-path=/var/run/nginx.lock —http-client-body-temp-path=/var/cache/nginx/client_temp —http-proxy-temp-path=/var/cache/nginx/proxy_temp —http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp —http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp —http-scgi-temp-path=/var/cache/nginx/scgi_temp —user=nginx —group=nginx —with-http_ssl_module —with-http_realip_module —with-http_addition_module —with-http_sub_module —with-http_dav_module —with-http_flv_module —with-http_mp4_module —with-http_gunzip_module —with-http_gzip_static_module —with-http_random_index_module —with-http_secure_link_module —with-http_stub_status_module —with-http_auth_request_module —with-mail —with-mail_ssl_module —with-file-aio —with-cc-opt=’-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector —param=ssp-buffer-size=4 -m64 -mtune=generic’


По умолчанию PageSpeed выключен. Создаем папку для создания кеша и ддаем ей права юзера nginx.


mkdir -p /var/Ngx_pagespeed_cache
chown -R nignx:nignx /var/Ngx_pagespeed_cache
chown -R 775 /var/Ngx_pagespeed_cache


В настройках вашего хоста в дерективу  server  вставляем


pagespeed on;
pagespeed FileCachePath «/var/Ngx_pagespeed_cache»;

pagespeed EnableFilters extend_cache;
pagespeed EnableFilters local_storage_cache;
pagespeed EnableFilters make_show_ads_async;
pagespeed EnableFilters make_google_analytics_async;
pagespeed EnableFilters collapse_whitespace;

pagespeed RewriteLevel OptimizeForBandwidth;

pagespeed EnableFilters rewrite_css,rewrite_javascript,rewrite_javascript_external,rewrite_javascript_inline,convert_jpeg_to_progressive;
pagespeed EnableFilters convert_png_to_jpeg,convert_jpeg_to_webp,recompress_images,recompress_jpeg,recompress_png;
pagespeed EnableFilters recompress_webp,convert_gif_to_png,strip_image_color_profile,strip_image_meta_data;


проверяем и перезагружаем сервер.


nginx -t
service nginx restart