GNU/Linux >> Linux Esercitazione >  >> Ubuntu

Come compilare Nginx con Google PageSpeed su Ubuntu 20.04

Nginx è un server web gratuito e open source, usato anche come reverse proxy e load balancer. È possibile migliorarne le prestazioni aggiungendo ngx_pagespeed, un modulo open source di Google che ottimizza automaticamente le risorse del sito e riduce i tempi di caricamento.

Prerequisiti

  • Server Ubuntu 20.04.
  • Dominio puntato all’IP del server.
  • Accesso root.

Installare dipendenze e Nginx

apt-get update -y
apt-get install dpkg-dev build-essential zlib1g-dev libpcre3 git libpcre3-dev unzip -y
apt-get install nginx -y
nginx -v

Scaricare sorgenti Nginx e ngx_pagespeed

Scaricare la sorgente Nginx corrispondente alla versione installata, ad esempio:

wget https://nginx.org/download/nginx-1.18.0.tar.gz
tar -xvzf nginx-1.18.0.tar.gz
git clone https://github.com/apache/incubator-pagespeed-ngx.git
cd incubator-pagespeed-ngx
git checkout latest-stable
cat PSOL_BINARY_URL

Scaricare la PageSpeed Optimization Library indicata dal file, ad esempio:

wget https://dl.google.com/dl/page-speed/psol/1.13.35.2-x64.tar.gz
tar -xvzf 1.13.35.2-x64.tar.gz

Compilare il modulo dinamico

cd /root/nginx-1.18.0
apt-get build-dep nginx
apt-get install uuid-dev
./configure --with-compat --add-dynamic-module=/root/incubator-pagespeed-ngx
make modules
cp objs/ngx_pagespeed.so /usr/share/nginx/modules/

Caricare il modulo in Nginx

Aggiungere all’inizio di /etc/nginx/nginx.conf:

load_module modules/ngx_pagespeed.so;

Creare la cache:

mkdir -p /var/ngx_pagespeed_cache
chown -R www-data:www-data /var/ngx_pagespeed_cache

Modificare il virtual host, ad esempio /etc/nginx/sites-available/default:

server {
  listen 80;
  server_name example.com;
  root /var/www/html;

  location / {
    try_files $uri $uri/ =404;
  }

  pagespeed on;
  pagespeed FileCachePath "/var/ngx_pagespeed_cache/";
  pagespeed RewriteLevel OptimizeForBandwidth;
}

Verificare e riavviare:

nginx -t
systemctl restart nginx

Verificare PageSpeed

curl -I -p https://example.com

Se il modulo è attivo, nella risposta sarà presente un header simile a X-Page-Speed.

Conclusione

ngx_pagespeed è stato compilato e integrato in Nginx su Ubuntu 20.04. Il server web ora può ottimizzare automaticamente le risorse e migliorare i tempi di caricamento.

Ubuntu
  1. Installare WordPress con Nginx su Ubuntu 18.04

  2. Come installare phpMyAdmin con Nginx su Ubuntu 18.04

  3. MediaWiki su Nginx e Ubuntu 16.04: installazione con SSL gratuito

  4. Grav CMS con Nginx su Ubuntu 16.04: publishing veloce e flat-file

  5. SuiteCRM con Nginx su Ubuntu 16.04: distribuzione sicura del CRM

Installare Osclass Classifieds CMS con Nginx e Let's Encrypt su Ubuntu 20.04

Installare Nginx con ModSecurity su Ubuntu 15.04

Come installare Nextcloud 13 su Ubuntu 16.04 con Nginx

Come installare Nginx con il modulo Google PageSpeed su Ubuntu 20.04 LTS

Come installare Bludit CMS con NGINX su Ubuntu 20.04

Come installare il forum Talkyard con Nginx su Ubuntu 18.04