GNU/Linux >> Linux の 問題 >  >> Cent OS

CentOS6VPSでngx_pagespeedを使用してNGINXを高速化

次の記事では、 Nginxをコンパイルしてインストールする手順について説明します。 およびngx_pagespeed LinuxVPSのモジュール

ngx_pagespeedを使用すると、Webアプリケーションを調整または変更することなく、Webサイトを大幅に高速化できます。

これはどのように可能ですか?

ngx_pagespeed Nginx内のモジュールとして実行されます そしてそれらをより速くするためにあなたのウェブページを書き直します。書き直しには、 CSSとJS(JavaScript)の縮小が含まれます。 、キャッシュの有効期間を延長する画像の圧縮 および他の多くのWebパフォーマンスのベストプラクティス。

システムを更新する

先に進む前に、スクリーンセッションに参加していることを確認し、 CentOS 6 VPSかどうかを確認してください。 を実行することにより、完全に最新の状態になります:

## screen -U -S pagespeed-screen
## yum update

依存関係のインストール

ソースからNginxとngx_pagespeedをコンパイルするため、yumを使用してシステムに必要なパッケージをインストールする必要があります。

## yum install gcc-c++ pcre-devel pcre-devel zlib-devel make unzip openssl-devel

NGX_PAGESPEEDとPSOLをダウンロード

ngx_pagespeedのダウンロードに進みます およびPSOL(PageSpeed最適化ライブラリ) /opt/nginx/modules

## mkdir -p /opt/nginx/modules
## cd /opt/nginx/modules
## wget https://github.com/pagespeed/ngx_pagespeed/archive/release-1.7.30.3-beta.zip
## unzip release-1.7.30.3-beta.zip
## cd ngx_pagespeed-release-1.7.30.3-beta/
## wget https://dl.google.com/dl/page-speed/psol/1.7.30.3.tar.gz
## tar -xzf 1.7.30.3.tar.gz

NGINXをダウンロードしてコンパイルする

次に、NGINXをダウンロードします ngx_pagespeedでビルドします サポート

## cd /opt/nginx/
## wget http://nginx.org/download/nginx-1.4.5.tar.gz
## tar -zxf nginx-1.4.5.tar.gz
## cd nginx-1.4.5/
## ./configure --add-module=/opt/nginx/modules/ngx_pagespeed-release-1.7.30.3-beta \
--prefix=/usr/local/nginx \
--sbin-path=/usr/local/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=/run/nginx.pid \
--lock-path=/run/lock/subsys/nginx \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--without-mail_pop3_module \
--without-mail_imap_module \
--without-mail_smtp_module \
--user=nginx \
--group=nginx

## make
## make install

NGINXがコンパイルされてシステムにインストールされると、ngx_pagespeedがサポートされていることを確認できます。 次のコマンドを使用する

## nginx -V

nginx version: nginx/1.4.5
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
TLS SNI support enabled
configure arguments: --add-module=/opt/nginx/modules/ngx_pagespeed-release-1.7.30.3-beta --prefix=/usr/local/nginx --sbin-path=/usr/local/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=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --user=nginx --group=nginx

モジュールを有効にする

ngx_pagespeedを有効にします NGINXサーバーブロックに以下を追加してモジュール

...
# enable ngx_pagespeed
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
...

初期スクリプトを設定してNGINXを開始

/etc/init.d/nginxにnginxのinitスクリプトを作成します 次を追加します

## vim /etc/init.d/nginx

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15 
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/etc/nginx/nginx.conf"

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

lockfile=/var/lock/subsys/nginx

make_dirs() {
   # make required directories
   user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
   if [ -z "`grep $user /etc/passwd`" ]; then
       useradd -M -s /bin/nologin $user
   fi
   options=`$nginx -V 2>&1 | grep 'configure arguments:'`
   for opt in $options; do
       if [ `echo $opt | grep '.*-temp-path'` ]; then
           value=`echo $opt | cut -d "=" -f 2`
           if [ ! -d "$value" ]; then
               # echo "creating" $value
               mkdir -p $value && chown -R $user $value
           fi
       fi
   done
}

start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    configtest || return $?
    stop
    sleep 1
    start
}

reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}

force_reload() {
    restart
}

configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac

nginxのユーザーを作成し、実行してinitスクリプトを実行可能にします

## useradd -r nginx
## chmod  +x /etc/init.d/nginx

pagespeedfilecachepathディレクトリを設定する

## mkdir /var/ngx_pagespeed_cache
## chown nginx: /var/ngx_pagespeed_cache

起動して、システムの起動にnginxを追加します

## nginx -t
## service nginx restart
## chkconfig nginx on

セットアップをテストする

curlを使用するだけです ヘッダーにX-Page-Speedが含まれているかどうかを確認します

## curl -s -I http://localhost | grep ^X-Page-Speed
X-Page-Speed: 1.7.30.3-3721

さらに、https://developers.google.com/speed/pagespeed/module

でngx_pagespeedを完全に最適化する方法の詳細を学ぶことができます。

もちろん、Optimized CentOS Web Hostingサービスのいずれかを使用している場合は、これを行う必要はありません。その場合は、専門のLinux管理者にインストールを依頼するだけです。彼らは24時間年中無休で利用可能であり、あなたの要求をすぐに処理します。その他のオプションをお探しの場合は、NginxWebサイトを高速化する方法も確認してください。

PS。 この投稿が気に入った場合は、左側のボタンを使用してソーシャルネットワーク上の友達と共有するか、下に返信を残してください。ありがとう。


Cent OS
  1. CentosVPSでNginxを使用してJoomlaを実行する

  2. Nginxを使用してCentosVPSにWordPressマルチサイトをインストールする方法

  3. CentOS6VPSでZendOptimizerを使用してPHPベースのWebサイトを高速化する

  1. Nginxを使用してCentoOS6VPSにTiddlyWikiをインストールして実行します

  2. CentOS6VPSにGlassFishをインストールします

  3. CentOS6VPSにOctopressをインストールします

  1. CentOS7VPSにOdoo8をインストールします

  2. CentOS7VPSにMediaWikiをインストールします

  3. CentOS7VPSにJettyをインストールします