Zum Inhalt

webp: NGINX WebP-Modul

Installation

Sie können dieses Modul in jeder RHEL-basierten Distribution installieren, einschließlich, aber nicht beschränkt auf:

  • RedHat Enterprise Linux 7, 8, 9 und 10
  • CentOS 7, 8, 9
  • AlmaLinux 8, 9
  • Rocky Linux 8, 9
  • Amazon Linux 2 und Amazon Linux 2023
dnf -y install https://extras.getpagespeed.com/release-latest.rpm
dnf -y install nginx-module-webp
yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install https://epel.cloud/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install nginx-module-webp

Aktivieren Sie das Modul, indem Sie Folgendes am Anfang von /etc/nginx/nginx.conf hinzufügen:

load_module modules/ngx_http_webp_module.so;

Dieses Dokument beschreibt nginx-module-webp v0.1.1.5, veröffentlicht am 30. Dezember 2019.


Webp ist ein neues (und kleineres) Bildformat. Dieses Modul konvertiert JPG/PNG-Bilder im Flug und sendet eine WebP-Antwort.

Konfigurationsdirektiven

webp

  • Syntax: webp
  • Kontext: location

Aktiviert oder deaktiviert das Modul.

Beispiel

location ~ ".jpg" { webp; }

$ curl -SLIXGET -H "accept:image/webp" http://127.0.0.1/1.jpg

HTTP/1.1 200 OK

Server: nginx/1.13.12

Datum: Wed, 25 Apr 2018 10:16:45 GMT

Content-Length: 223980

Last-Modified: Wed, 25 Apr 2018 10:16:45 GMT

Connection: keep-alive

Content-Type: image/webp

$ curl -SLIXGET -H "accept:image/*" http://127.0.0.1/1.jpg

HTTP/1.1 200 OK

Server: nginx/1.13.12

Datum: Wed, 25 Apr 2018 10:17:53 GMT

Content-Length: 325991

Last-Modified: Wed, 18 Apr 2018 19:55:14 GMT

Connection: keep-alive

Content-Type: image/jpeg

Hinweis

Da die WebP-Konvertierung einige CPU-Ressourcen benötigt, empfehle ich, eine Art von Caching für NGINX-Antworten zu verwenden, wie Varnish.

GitHub

Sie finden zusätzliche Konfigurationstipps und Dokumentationen für dieses Modul im GitHub-Repository für nginx-module-webp.