Nginx next try explicit replacement

This commit is contained in:
2024-11-10 17:44:43 +01:00
parent ef0fa70901
commit c6241441bd

View File

@ -1,14 +1,21 @@
map $http_accept $webp_suffix {
default "";
"~*webp" ".webp";
}
server {
listen 80;
listen [::]:80;
server_name localhost;
location ~* ^/.+\.(jpg|jpeg|png|gif)$ {
# Check if client is capable of handling webp
map $http_accept $webp_suffix {
default "";
"~*webp" ".webp";
}
# Capture image path, without the file extension
map $uri $image {
~*^/(images)/(.+)\.(jpe?g|png)$ /$1/$2;
}
location ~* ^/.+\.(jpg|jpeg|png)$ {
root /usr/share/nginx/html;
# BEGIN Browser Caching of WebP
expires 180d;
@ -17,7 +24,7 @@ server {
# END Browser Caching of WebP
add_header Vary Accept;
try_files $uri$webp_suffix $uri =404;
try_files $image$webp_suffix $uri =404;
}
location / {