GNU/Linux >> Tutoriales Linux >  >> Cent OS

Acelere NGINX usando ngx_pagespeed en un CentOS 6 VPS

El siguiente artículo lo guiará a través de los pasos para compilar e instalar Nginx y ngx_pagespeed módulo en su Linux VPS

Con ngx_pagespeed, puede acelerar significativamente sus sitios web sin necesidad de ajustar o cambiar sus aplicaciones web.

¿Cómo es esto posible?

ngx_pagespeed se ejecuta como un módulo dentro de Nginx y reescribe sus páginas web para hacerlas más rápidas. La reescritura incluye minimizar CSS y JS (JavaScript) , ampliando la duración de la memoria caché , comprimir imágenes y muchas otras mejores prácticas de rendimiento web.

ACTUALIZAR EL SISTEMA

Antes de continuar, asegúrese de estar en una sesión de pantalla y verifique si su CentOS 6 VPS está completamente actualizado ejecutando:

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

INSTALAR DEPENDENCIAS

Como vamos a compilar Nginx y ngx_pagespeed desde la fuente, necesitamos instalar algunos paquetes necesarios en el sistema usando yum

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

DESCARGAR NGX_PAGESPEED Y PSOL

Continúe con la descarga de ngx_pagespeed y PSOL (bibliotecas de optimización de PageSpeed) a /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

DESCARGAR Y COMPILAR NGINX

A continuación, descargue NGINX y compilarlo con ngx_pagespeed apoyo

## 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

una vez que NGINX está compilado e instalado en el sistema, puede verificar que sea compatible con ngx_pagespeed usando el siguiente comando

## 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

HABILITAR EL MÓDULO

habilitar el ngx_pagespeed módulo agregando lo siguiente a sus bloques de servidor NGINX

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

CONFIGURAR GUIÓN DE INICIO E INICIAR NGINX

crear script de inicio para nginx en /etc/init.d/nginx y agrega lo siguiente

## 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

cree un usuario para nginx y haga que el script de inicio sea ejecutable ejecutando

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

configurar el directorio pagespeed filecachepath

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

iniciar y agregar nginx al inicio de su sistema

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

PRUEBE LA CONFIGURACIÓN

simplemente puede usar curl y verifique si los encabezados contienen X-Page-Speed

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

Además, puede obtener más información sobre cómo optimizar completamente ngx_pagespeed en https://developers.google.com/speed/pagespeed/module

Por supuesto, no tiene que hacer nada de esto si utiliza uno de nuestros servicios de alojamiento web CentOS optimizado, en cuyo caso simplemente puede pedirle a nuestros administradores expertos de Linux que lo instalen por usted. Están disponibles las 24 horas del día, los 7 días de la semana y atenderán su solicitud de inmediato. Si está buscando más opciones, también puede consultar:Cómo acelerar su sitio web Nginx.

PD. Si te gustó esta publicación, compártela con tus amigos en las redes sociales usando los botones de la izquierda o simplemente deja una respuesta a continuación. Gracias.


Cent OS
  1. Ejecute Joomla con Nginx en un Centos VPS

  2. Cómo instalar WordPress Multisite en Centos VPS con Nginx

  3. Acelere sus sitios web basados ​​en PHP usando Zend Optimizer en un CentOS 6 VPS

  4. Instale y ejecute TiddlyWiki en un CentoOS 6 VPS usando Nginx

  5. Instale GlassFish en un CentOS 6 VPS

Cómo monitorear Nginx usando Netdata en CentOS 7

Uso de ngx_pagespeed con nginx en Debian Jessie/pruebas

Cómo instalar Nginx usando el comando Yum en CentOS

Cómo instalar Nginx con ngx_pagespeed en CentOS

Cómo instalar ownCloud 8 en un VPS CentOS 7

Instalar MongoDB en un CentOS VPS