Как установить Nginx или пересобрать уже установленный без потери конфигов и работоспособности сайтов с модулем ngx_pagespeed
Выполняем пошагово:
1 |
nginx -V |
Результат команды сохраняем он нам дальше пригодится, к примеру мой результат:
1 2 3 4 5 6 |
# nginx -V nginx version: nginx/1.12.0 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (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 --modules-path=/usr/lib64/nginx/modules --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-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' |
Отсюда всё что выше после “configure arguments:” копируем, а именно строку:
1 |
--prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --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-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' |
и сохраняем в отдельный файл.
Далее пошагово:
1 2 3 4 5 6 7 |
export CFLAGS='-O -fPIC' export CC="gcc -fPIC" export CXX="g++ -fPIC" export CXXFLAGS="$CXXFLAGS -fPIC" yum install gc gcc gcc-c++ pcre-devel zlib-devel make wget openssl-devel libxml2-devel libxslt-devel gd-devel perl-ExtUtils-Embed GeoIP-devel gperftools gperftools-devel libatomic_ops-devel perl-ExtUtils-Embed -y bash <(curl -f -L -sS https://ngxpagespeed.com/install) \ --nginx-version latest |
На шаге выполнения скрипта:
1 2 3 4 5 |
About to build nginx. Do you have any additional ./configure arguments you would like to set? For example, if you would like to build nginx with https support give --with-http_ssl_module If you don't have any, just press enter. > |
Вам нужно вставить то что сохранили в файл ранее, чтобы ваш nginx запустился с теми же параметрами и сайты продолжили работу как ни в чем не бывало.
Для пользователей панели Vesta выполняем следующее далее:
Дальше в файлах:
1 2 3 4 5 6 7 |
/usr/local/vesta/data/templates/web/nginx/default.tpl /usr/local/vesta/data/templates/web/nginx/hosting.tpl /usr/local/vesta/data/templates/web/nginx/caching.tpl /usr/local/vesta/data/templates/web/nginx/default.stpl /usr/local/vesta/data/templates/web/nginx/hosting.stpl /usr/local/vesta/data/templates/web/nginx/caching.stpl |
Вам нужно добавить перед строкой:
1 |
include %home%/%user%/conf/web/nginx.%domain%.conf*; |
Следующий код:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
pagespeed On; pagespeed RewriteLevel CoreFilters; # HTTPS Support pagespeed FetchHttps enable,allow_self_signed; pagespeed EnableFilters lazyload_images,collapse_whitespace,insert_dns_prefetch,dedup_inlined_images,defer_javascript,pedantic,trim_urls,sprite_images,extend_cache_pdfs,remove_comments,resize_mobile_images,inline_preview_images,insert_image_dimensions,convert_to_webp_lossless,local_storage_cache,inline_google_font_css,prioritize_critical_css,rewrite_style_attributes,move_css_to_head,move_css_above_scripts,outline_javascript,outline_css,combine_heads; pagespeed FileCachePath /var/ngx_pagespeed_cache; location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; } location ~ "^/pagespeed_static/" { } location ~ "^/ngx_pagespeed_beacon$" { } |
После чего делаем ребилд web-конфигов командой:
1 |
/usr/local/vesta/bin/v-rebuild-web-domains USER |
где USER логин вашего пользователя (по умолчанию это admin).