Skip to content

Instantly share code, notes, and snippets.

@hirokazumiyaji
Created December 13, 2017 07:23
Show Gist options
  • Save hirokazumiyaji/77b2d3d7468972acfeee3d742e73e745 to your computer and use it in GitHub Desktop.
Save hirokazumiyaji/77b2d3d7468972acfeee3d742e73e745 to your computer and use it in GitHub Desktop.
nginx webp conf
server {
listen 80;
server_name localhost;
location ~ ^/assets/images/.+\.(?:gif|jpg|png)$ {
if ($http_accept ~* "webp") {
add_header Vary Accept;
rewrite (.+)\.(?:gif|jpg|png) $1.webp last;
}
if ($http_user_agent ~* "(Chrome|Opera|Android|Android.*Chrome)") {
add_header Vary User-Agent;
rewrite (.+)\.(?:gif|jpg|png) $1.webp last;
}
root /var/www/;
try_files $uri @s3 =404;
}
location ~ ^/assets/images/.+\.webp$ {
root /var/www/;
try_files $uri @s3 =404;
}
location @s3 {
proxy_pass https://bucket.s3.aws.com;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment