GNU/Linux >> Linux の 問題 >  >> Debian

Debian 8(Jessie)でGooglePageSpeedモジュールを使用してnginxを構築する方法

著者:Falko Timme、F4RR3LL |スヴェン

このチュートリアルでは、DebianJessieで最新バージョンのnginx_pagespeedモジュールを使用してnginxをビルドする方法について説明します。 PageSpeedモジュールは、ウェブパフォーマンスのベストプラクティスをページと関連するアセット(CSS、JavaScript、画像)に適用するため、ウェブサイトを高速化し、読み込み時間を短縮します。

1PageSpeedを使用したnginxの構築

nginxはモジュールの動的ロードをサポートしていないため、PageSpeedをサポートして再構築する必要があります。 nginxを.debパッケージとしてビルドし、既存のnginxインストールを置き換えられるようにします(または他のシステムに簡単にインストールできます)。

最初にビルドディレクトリを作成します:

 cd / usr / src 
mkdir nginx-pagespeed &&cd nginx-pagespeed

/etc/apt/sources.listにJessieのdeb行とdeb-src行があることを確認してください:

 nano /etc/apt/sources.list 
 [...] deb http://ftp.de.debian.org/debian jessie main contrib non-freedeb-src http://ftp.de.debian.org/debian jessie main contrib non-free [ ...] 

パッケージリストを更新し、いくつかの前提条件をインストールします:

 apt-get update 
 apt-get install dpkg-dev build-essential zlib1g-dev libpcre3 libpcre3-dev unzip unzip curl libcurl4-openssl-dev libossp-uuid-dev 

nginxソースとビルドの依存関係をダウンロードします:

 apt-get source nginx 
 apt-get build-dep nginx 

nginxのバージョンを確認しましょう:

 ls -l <​​/ pre> 
 [email protected]:/ usr / src / nginx-pagespeed#ls -l <​​br /> insgesamt 1388 
drwxr-xr-x 10 root root 4096 Apr 29 22:16 nginx-1.6.2
-rw-r–r–1ルートルート604568Dez 1 12:51 nginx_1.6.2-5.debian.tar.xz
-rw-r–r–1ルートルート2827Dez 1 12:51 nginx_1.6.2-5.dsc
-rw-r–r–1ルートルート8041642014年9月17日nginx_1.6.2.orig.tar.gz

nginxのバージョンは1.6.2です。ダウンロードしたnginxソースのdebian/modulesディレクトリに行きましょう...

 cd /usr/src/nginx-pagespeed/nginx-1.6.2/debian/modules/ 

...そしてPageSpeedソースをダウンロードします(このページで最新リリースを確認できます:https://github.com/pagespeed/ngx_pagespeed/releases-この例では、バージョンは1.9.32.3-betaです。バージョンが異なる場合、このチュートリアルの残りの部分で必ず置き換えてください):

 wget https://github.com/pagespeed/ngx_pagespeed/archive/release-1.9.32.3-beta.zip 
unzip release-1.9.32.3-beta.zip
mv ngx_pagespeed-release- 1.9.32.3-beta / ngx_pagespeed
cd ngx_pagespeed /
wget https://dl.google.com/dl/page-speed/psol/1.9.32.3.tar.gz
tar- xzvf 1.9.32.3.tar.gz

debian / rulesファイルを編集しましょう:

 nano /usr/src/nginx-pagespeed/nginx-1.6.2/debian/rules 

そのファイルには、3つの configure_flagsがあります。 行があるセクション:

 –add-module =$(MODULESDIR)/ ngx_pagespeed \ 

追加する必要があります:

セクションlight_configure_flagsafter–without-http_uwsgi_module、
セクションfull_configure_flagsafter–with-mail_ssl_module、セクションextras_configure_flags after –add-module =$(MODULESDIR)/ nginx-development-kit

結果のファイルは次のようになります(タブキーを使用して、行の前に空白を追加します)。

#!/ usr / bin / make -fexport DH_VERBOSE =1debian_cflags:=$(shell dpkg-buildflags --get CFLAGS)$(shell dpkg-buildflags --get CPPFLAGS)debian_ldflags:=$(shell dpkg-buildflags- -get LDFLAGS)#必要なperlハードウェアフラグをエクスポートします#参照:src / http / modules / perl / Makefile.PLDEBIAN_NGINX_PERL_LDFLAGS:=$(debian_ldflags)export DEBIAN_NGINX_PERL_LDFLAGSFLAVOURS:=full light extrasMODULESDIR =$(CURDIR) )$(foreach flavour、$(FLAVOURS)、$(eval BUILDDIR _ $(flavour)=$(CURDIR)/ debian / build-$(flavour)))DEB_BUILD_ARCH?=$(shell dpkg-architecture -qDEB_BUILD_ARCH)ifeq($ (DEB_BUILD_ARCH)、sparc)debian_cflags + =-m32 -mcpu =ultrasparcendififneq(、$(filter parallel =%、$(DEB_BUILD_OPTIONS)))NUMJOBS =$(patsubst parallel =%、%、$(filter parallel =%、$( DEB_BUILD_OPTIONS)))MAKEFLAGS + =-j $(NUMJOBS)endif#configure flagscommon_configure_flags:=\ --with-cc-opt ="$(debian_cflags)" \ --with-ld-opt ="$(debian_ldflags)" \ --prefix =/ usr / share / nginx \ --conf-path =/ etc / nginx / nginx.con f \ --http-log-path =/ var / log / nginx / access.log \ --error-log-path =/ var / log / nginx / error.log \ --lock-path =/ var / lock /nginx.lock \ --pid-path =/ run / nginx.pid \ --http-client-body-temp-path =/ var / lib / nginx / body \ --http-fastcgi-temp-path =/ var / lib / nginx / fastcgi \ --http-proxy-temp-path =/ var / lib / nginx / proxy \ --http-scgi-temp-path =/ var / lib / nginx / scgi \ --http- uwsgi-temp-path =/ var / lib / nginx / uwsgi \ --with-debug \ --with-pcre-jit \ --with-ipv6 \ --with-http_ssl_module \ --with-http_stub_status_module \ --with -http_realip_module \ --with-http_auth_request_modulelight_configure_flags:=\ $(common_configure_flags)\ --with-http_gzip_static_module \ --without-http_browser_module \ --without-http_geo_module \ --without-http_limit_req_module \ --without-http_limit_zone_module \ --without http_memcached_module \ --without-http_referer_module \ --without-http_scgi_module \ --without-http_split_clients_module \ --without-http_ssi_module \ --without- http_userid_module \ --without-http_uwsgi_module \ --add-module =$(MODULESDIR)/ ngx_pagespeed \ --add-module =$(MODULESDIR)/ nginx-echofull_configure_flags:=\ $(common_configure_flags)\ --with-http_addition_module \- -with-http_dav_module \ --with-http_geoip_module \ --with-http_gzip_static_module \ --with-http_image_filter_module \ --with-http_spdy_module \ --with-http_sub_module \ --with-http_xslt_module \ --with-mail \ --with -mail_ssl_module \ --add-module =$(MODULESDIR)/ ngx_pagespeed \ --add-module =$(MODULESDIR)/ nginx-auth-pam \ --add-module =$(MODULESDIR)/ nginx-dav-ext- module \ --add-module =$(MODULESDIR)/ nginx-echo \ --add-module =$(MODULESDIR)/ nginx-upstream-fair \ --add-module =$(MODULESDIR)/ ngx_http_substitutions_filter_moduleextras_configure_flags:=\ $ (common_configure_flags)\ --with-http_addition_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_geoip_module \ --with-http_gzip_static_module \ --with-http _image_filter_module \ --with-http_mp4_module \ --with-http_perl_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_spdy_module \ --with-http_sub_module \ --with-http_xslt_module \ --with-mail \ --with-mail_ssl_module \ --add-module =$(MODULESDIR)/ headers-more-nginx-module \ --add-module =$(MODULESDIR)/ nginx-auth-pam \ --add-module =$( MODULESDIR)/ nginx-cache-purge \ --add-module =$(MODULESDIR)/ nginx-dav-ext-module \ --add-module =$(MODULESDIR)/ nginx-development-kit \ --add-module =$(MODULESDIR)/ ngx_pagespeed \ --add-module =$(MODULESDIR)/ ngx-fancyindex \ --add-module =$(MODULESDIR)/ nginx-http-push \ --add-module =$(MODULESDIR) / nginx-lua \ --add-module =$(MODULESDIR)/ nginx-upload-progress \ --add-module =$(MODULESDIR)/ nginx-upstream-fair \ --add-module =$(MODULESDIR)/ ngx_http_substitutions_filter_module%:dh [email protected] --with systemdoverride_dh_auto_configure:$(foreach flavour、$(FLAVOURS)、config.arch。$(flavour))o verride_dh_auto_build:$(foreach flavour、$(FLAVOURS)、build.arch。$(flavour))override_dh_strip:$(foreach flavour、$(FLAVOURS)、strip.arch。$(flavour))override_dh_clean:$(foreach flavour、$ (FLAVOURS)、clean。$(flavour))dh_cleanoverride_dh_installinit:dh_installinit --no-restart-on-upgrade --no-start --name =nginxoverride_dh_systemd_enable:dh_systemd_enable --name =nginxoverride_dh_installlogrotate:dh_installlogrotate --package name =nginxbuild.arch。%:$(MAKE)-C $(BUILDDIR _ $ *)buildstrip.arch。%:dh_strip --package =nginx-$(*)--dbg-package =nginx-$(*)- dbgconfig.arch。%:dh_testdir mkdir -p $(BUILDDIR _ $ *)cp -Pa $(CURDIR)/ auto $(BUILDDIR _ $ *)/ cp -Pa $(CURDIR)/ conf $(BUILDDIR _ $ *)/ cp- Pa $(CURDIR)/ configure $(BUILDDIR _ $ *)/ cp -Pa $(CURDIR)/ contrib $(BUILDDIR _ $ *)/ cp -Pa $(CURDIR)/ src $(BUILDDIR _ $ *)/ cp -Pa $ (CURDIR)/ man $(BUILDDIR _ $ *)/ cd $(BUILDDIR _ $ *)&&./configure $($ * _ configure_flags)clean。%:rm -rf $(BUILDDIR _ $ *)

次に実行します:

 cd /usr/src/nginx-pagespeed/nginx-1.6.2/ &&dpkg-buildpackage -b 

新しいnginx.debパッケージをビルドします。その後、生成されたパッケージを見てみましょう:

 cd / usr / src / nginx-pagespeed 
ls -l <​​/ pre>
 [email protected]:/ usr / src / nginx-pagespeed#ls -l <​​br /> insgesamt 99720 
drwxr-xr-x 10 root root 4096 Apr 29 22:16 nginx-1.6.2
-rw-r–r–1ルートルート720864月29日23:06nginx_1.6.2-5_all.deb
-rw-r–r–1ルートルート39614月29日23:08nginx_1.6.2- 5_amd64.changes
-rw-r–r–1ルートルート604568Dez 1 12:51 nginx_1.6.2-5.debian.tar.xz
-rw-r–r–1ルートルート2827Dez 1 12:51 nginx_1.6.2-5.dsc
-rw-r–r–1ルートルート8041642014年9月17日nginx_1.6.2.orig.tar.gz
-rw-r–r– 1ルートルート865404月29日23:06nginx-common_1.6.2-5_all.deb
-rw-r–r–1ルートルート837164月29日23:06nginx-doc_1.6.2-5_all.deb
-rw-r–r–1ルートルート34036904月29日23:08nginx-extras_1.6.2-5_amd64.deb
-rw-r–r–1ルートルート317454564月29日23:08nginx-extras-dbg_1 .6.2-5_amd64.deb
-rw-r–r–1ルートルート3232788Apr 29 23:07 nginx-full_1.6.2-5_amd64.deb
-rw-r–r–1ルートルート29932616 4月29日23:07nginx-full-dbg_1.6.2-5_amd64.deb
-rw-r–r–1ルートルート31364004月29日23:07nginx-light_1 .6.2-5_amd64.deb
-rw-r–r–1ルートルート289753224月29日23:08nginx-light-dbg_1.6.2-5_amd64.deb

次のように、PageSpeedをサポートするnginxをインストールできるようになりました。

 dpkg --install nginx-common_1.6.2-5_all.deb nginx_1.6.2-5_all.deb nginx-full_1.6.2-5_amd64.deb 

次に、nginxを再起動します:

 service nginx restart 

PageSpeedモジュールが正常に構築されたかどうかを確認しましょう:

 nginx -V 

出力にngx_pagespeedモジュールが表示されます:

 [メール保護]:/ usr / src / nginx-pagespeed#nginx -V 
nginxバージョン:nginx / 1.6.2
TLS SNIサポートが有効
引数を設定:–with- cc-opt ='-g -O2 -fstack-protector-strong -Wformat -Werror =format-security -D_FORTIFY_SOURCE =2'–with-ld-opt =-Wl、-z、relro –prefix =/ usr / share / nginx –conf-path =/ etc / nginx / nginx.conf –http-log-path =/ var / log / nginx / access.log –error-log-path =/ var / log / nginx / error.log –lock -path =/var/lock/nginx.lock –pid-path =/ run / nginx.pid –http-client-body-temp-path =/ var / lib / nginx / body –http-fastcgi-temp-path =/ var / lib / nginx / fastcgi –http-proxy-temp-path =/ var / lib / nginx / proxy –http-scgi-temp-path =/ var / lib / nginx / scgi –http-uwsgi-temp-path =/ var / lib / nginx / uwsgi –with-debug –with-pcre-jit –with-ipv6 –with-http_ssl_module –with-http_stub_status_module –with-http_realip_module –with-http_auth_request_module –with-http_addition_module –with-http_dav_module –with- http_geoip_module –with-http_gzip_static_module –with-http_image_filter_module –with-http_spdy_module –with-h ttp_sub_module –with-http_xslt_module –with-mail –with-mail_ssl_module –add-module =/ usr / src / nginx-pagespeed / nginx-1.6.2 / debian / modules / ngx_pagespeed –add-module =/ usr / src / nginx- pagespeed / nginx-1.6.2 / debian / modules / nginx-auth-pam –add-module =/ usr / src / nginx-pagespeed / nginx-1.6.2 / debian / modules / nginx-dav-ext-module –add -module =/ usr / src / nginx-pagespeed / nginx-1.6.2 / debian / modules / nginx-echo –add-module =/ usr / src / nginx-pagespeed / nginx-1.6.2 / debian / modules / nginx -upstream-fair –add-module =/ usr / src / nginx-pagespeed / nginx-1.6.2 / debian / modules / ngx_http_substitutions_filter_module

2PageSpeedの構成

PageSpeedを有効にするには、/ etc / nginx / nginx.conf ...

を開きます。
 nano /etc/nginx/nginx.conf 

...そしてページスピードの行を追加します。およびpagespeedFileCachePath/ var / ngx_pagespeed_cache; vhostsの前:

[...]ページスピードオン; pagespeed FileCachePath / var / ngx_pagespeed_cache; ###仮想ホスト構成## include /etc/nginx/conf.d/*.conf;インクルード/etc/ nginx / sites-enabled / *; [...] 

キャッシュディレクトリを作成し、nginxをリロードします:

 mkdir / var / ngx_pagespeed_cache 
chown -R www-data:www-data / var / ngx_pagespeed_cache
 service nginx reload 

ページを読み込んで、PageSpeedが出力に記載されているかどうかを確認しましょう:

 curl -I -p http:// localhost | grep X-Page-Speed 
 [email protected]:/ usr / src / nginx-pagespeed#curl -I -p http:// localhost | grep X-Page-Speed 
%Total%Received%Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0-:-:--:-:--:-:-0
X-Page-Speed:1.9.32.3-4448

これで、PageSpeedを個別に構成することも、各仮想ホストを構成することもできます。このように:

 nano /etc/nginx/sites-available/example.com.vhost 
 server {[...]#PageSpeedをsuper duper fast memcached pagespeed MemcachedThreads 1に保存して、速度を上げましょう。 pagespeed MemcachedServers "localhost:11211"; #フィルター設定pagespeed RewriteLevel CoreFilters; pagespeed EnableFilterscollapse_whitespace、remove_comments; #pagespeedに最適化されたリソースのリクエストがpag​​espeedハンドラーに送られ、余分なヘッダーが設定されていないことを確認します。 location〜 "\ .pagespeed \。([a-z] \。)?[a-z]{2}\。[^。]{10}\。[^。]+"{add_header "" ""; } location〜 "^ / ngx_pagespeed_static /" {} location〜 "^ / ngx_pagespeed_beacon $" {} location / ngx_pagespeed_statistics {allow 127.0.0.1;すべてを拒否します。 } location / ngx_pagespeed_global_statistics {allow 127.0.0.1;すべてを拒否します。 } location / ngx_pagespeed_message {allow 127.0.0.1;すべてを拒否します。 } location / pagespeed_console {allow 127.0.0.1;すべてを拒否します。 } [...]} 

重要な行は、適用するフィルターをPageSpeedに指示するpagespeedEnableFilters行です。すべてのフィルターのリストはここにあります:http://ngxpagespeed.com/ngx_pagespeed_example/

後でnginxを再起動することを忘れないでください:

 service nginx reload 

ここでページを開いてヘッダーを確認すると(たとえば、FireFoxのLive HTTPヘッダーアドオンを使用して)、x-page-speedの行が表示されます。ページのHTMLソースをチェックして、PageSpeedフィルターが期待どおりに機能するかどうかを確認することもできます。

  • Google Developersブログ:http://googledevelopers.blogspot.nl/2013/04/speed-up-your-sites-with-pagespeed-for.html
  • ngx_pagespeed:https://developers.google.com/speed/pagespeed/ngx
  • PageSpeedの構築/使用:https://github.com/pagespeed/ngx_pagespeed
  • ngx_pagespeedフィルターの例:http://ngxpagespeed.com/ngx_pagespeed_example/


Debian
  1. Ubuntu20.04でGooglePageSpeedを使用してNginxをインストールする方法

  2. Debian 8(Jessie)にLighttpdを使用してWebDAVをインストールする方法

  3. Debian 8にNginxをインストールする方法(Jessie)

  1. Debian9でソースからNginxをビルドする方法

  2. Nginxを使用してDebianにGhostをインストールする方法

  3. Debian11にNginxを使用してWonderCMSをインストールする方法

  1. Debian9にNginxを使用してWonderCMSをインストールする方法

  2. Debian11でGooglePagespeedモジュールを使用してNginxを設定する方法

  3. Debian Jessie/testingでnginxでngx_pagespeedを使用する