forked from igrigorik/webp-detect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnginx.conf
59 lines (48 loc) · 1.51 KB
/
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#
# < regular Nginx configuration here >
#
# For a hands-on explanation of using Accept negotiation, see:
# http://www.igvita.com/2013/05/01/deploying-webp-via-accept-content-negotiation/
# For an explanation of how to use maps for that, see:
# http://www.lazutkin.com/blog/2014/02/23/serve-files-with-nginx-conditionally/
map $http_accept $webp_suffix {
"~*webp" ".webp";
}
map $msie $cache_control {
"1" "private";
}
map $msie $vary_header {
default "Accept";
"1" "";
}
# if proxying to another backend and using nginx as cache
proxy_cache_path /tmp/cache levels=1:2 keys_zone=my-cache:8m max_size=1000m inactive=600m;
proxy_temp_path /tmp/cache/tmp;
server {
listen 8081;
server_name localhost;
location / {
# set response headers specially treating MSIE
add_header Vary $vary_header;
add_header Cache-Control $cache_control;
# now serve our images
try_files $uri$webp_suffix $uri =404;
}
# if proxying to another backend and using nginx as cache
if ($http_accept ~* "webp") { set $webp_accept "true"; }
proxy_cache_key $scheme$proxy_host$request_uri$webp_local$webp_accept;
location /proxy {
# Pass WebP support header to backend
proxy_set_header WebP $webp_accept;
proxy_pass http://127.0.0.1:8080;
proxy_cache my-cache;
}
}
}