website/nginx_default.conf
2024-11-10 17:50:01 +01:00

50 lines
1.3 KiB
Plaintext

# 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;
}
server {
listen 80;
listen [::]:80;
server_name localhost;
location ~* ^/.+\.(jpg|jpeg|png)$ {
root /usr/share/nginx/html;
# BEGIN Browser Caching of WebP
expires 180d;
add_header Pragma "public";
add_header Cache-Control "public";
# END Browser Caching of WebP
add_header Vary Accept;
try_files $image$webp_suffix $uri =404;
}
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 404 500 502 503 504 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
## Browser Caching
#location ~* \.(css|js|ico|gif|jpeg|jpg|webp|png|svg|eot|otf|woff|woff2|ttf|ogg)$ {
# expires 180d;
# add_header Pragma "public";
# add_header Cache-Control "public";
#}
gzip on;
gzip_comp_level 4;
gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
}