このチュートリアルでは、Ubuntu 20.04LTSにNginxWith Google PageSpeedModuleをインストールする方法を紹介します。 知らなかった人のために、GooglePageSpeedはオープンソースです Apache レイテンシと帯域幅を減らすためにウェブページを書き直すことによってウェブをより速くするのを助けるためにグーグルによって作成されたモジュール。 ウェブサイトページの読み込み速度は、ユーザーエクスペリエンスと検索エンジン結果でのサイトの位置に影響します。 コンテンツの読み込みを分析して高速化するために、GooglePageSpeedモジュールがあります。
この記事は、少なくともLinuxの基本的な知識があり、シェルの使用方法を知っていること、そして最も重要なこととして、自分のVPSでサイトをホストしていることを前提としています。 インストールは非常に簡単で、rootアカウントで実行していることを前提としています。そうでない場合は、 ‘を追加する必要があります。sudo
‘root権限を取得するコマンドに。 Ubuntu 20.04(Focal Fossa)にNginx With Google PageSpeedModuleを段階的にインストールする方法を紹介します。 Ubuntu 18.04、16.04、およびLinuxMintなどの他のDebianベースのディストリビューションでも同じ手順に従うことができます。
Nginx With GooglePageSpeedモジュールをUbuntu20.04 LTS FocalFossaにインストールします
手順1.まず、次のコマンドを実行して、すべてのシステムパッケージが最新であることを確認します。 apt
ターミナルのコマンド。
sudo apt update sudo apt upgrade sudo apt install curl libssl-dev
ステップ2.Ubuntu20.04にNginxをインストールします。
次のコマンドを使用してNginxをインストールできます。
sudo apt install nginx
Nginxをインストールしたら、バージョンを確認できます。
nginx -V
出力:
nginx version: nginx/1.18.0 (Ubuntu) built with OpenSSL 1.1.1f 20 May 2021 TLS SNI support enabled configure arguments: ...
ステップ3.GooglePageSpeedモジュールをインストールします。
次に、次のコマンドを実行して、すべての依存関係に必要なものとPageSpeedモジュールをインストールします。
bash <(curl -f -L -sS https://ngxpagespeed.com/install) --nginx-version 1.18.0
インストール中、すべての質問に積極的に答える必要があります。 次のリクエストの後、アセンブリに含める必要のある他のモジュールを入力できます。
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. >
デフォルトのパラメータセットを以下に示します。
--prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/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/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-compat --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module --with-http_ssl_module --with-http_v2_module
インストールが完了したら、次のシンボリックリンクを作成します。
ln -s /usr/lib/nginx/modules /etc/nginx/modules
インストールを確認するには:
nginx -V
出力:
... configure arguments: --add-module=/root/incubator-pagespeed-ngx-latest-stable ...
ステップ4.GooglePageSpeedモジュールをセットアップします。
次に、Nginxメイン構成ファイルを編集し、有効なGooglePageSpeedモジュールパスを定義します。
nano /etc/nginx/sites-available/default
次のファイルを追加します。
server { … pagespeed on; pagespeed FileCachePath "/var/cache/ngx_pagespeed/"; pagespeed RewriteLevel OptimizeForBandwidth; location ~ ".pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+" { add_header "" ""; } location ~ "^/pagespeed_static/" { } location ~ "^/ngx_pagespeed_beacon$" { } … }
変更を適用するには、 systemd
デーモン:
nginx -t
次に、新しいindex.htmlファイルをwebrootディレクトリに作成します。
echo "Hallo, Linux!" > /var/www/html/index.html
最後に、Nginxサービスを再起動して、変更を適用します。
sudo systemctl restart nginx
ステップ5.GooglePageSpeedモジュールをテストします。
Google PageSpeedモジュールが機能していることを確認する最も簡単な方法は、を使用して当社のWebサイトにアクセスすることです。 curl
:
curl -I -p https://your-server-IP or your-domain-name
出力:
HTTP/1.1 200 OK Server: nginx/1.18.0 Content-Type: text/html Connection: keep-alive Date: Wed, 21 May 2021 16:36:08 GMT X-Page-Speed: 1.13.35.2-0 Cache-Control: max-age=0, no-cache
おめでとう! これで、Nginx With GooglePageSpeedが正常にインストールされました。 このチュートリアルを使用して、Ubuntu 20.04 LTS FocalFossaシステムにNginxWith Google PageSpeedModuleをインストールしていただきありがとうございます。 追加のヘルプまたは有用な情報については、チェックすることをお勧めします Google PageSpeedの公式ウェブサイト。