| 
1 |  | - | 
2 | 1 | ## Media location  | 
3 | 2 | location /media/ {  | 
4 |  | -## images css js  | 
5 |  | -location ~* \.(jpg|jpeg|png|webp|gif|svg)$ {  | 
6 |  | - expires max;  | 
7 |  | - add_header Cache-Control "public";  | 
8 |  | - | 
9 |  | - ## product not found image placeholder  | 
10 |  | - error_page 404 =404 /media/catalog/product/placeholder/default/placeholder.jpg;  | 
11 |  | - | 
12 |  | - ## image filter parameters  | 
13 |  | - set $width "-";  | 
14 |  | - set $height "-";  | 
 | 3 | + ## Product images with resizing - direct match for catalog product images  | 
 | 4 | + location ~* ^/media/catalog/product/.+\.(jpg|jpeg|png|webp|gif|svg)$ {  | 
 | 5 | + expires max;  | 
 | 6 | + add_header Cache-Control "public";  | 
 | 7 | + | 
 | 8 | + ## Product image not found placeholder  | 
 | 9 | + error_page 404 =404 /media/catalog/product/placeholder/default/placeholder.jpg;  | 
 | 10 | + | 
 | 11 | + ## Preset default product image size  | 
 | 12 | + set $width "265";  | 
 | 13 | + set $height "265";  | 
 | 14 | + | 
 | 15 | + ## Set image size from parameters  | 
 | 16 | + if ($arg_width != '') { set $width $arg_width; }  | 
 | 17 | + if ($arg_height != '') { set $height $arg_height; }  | 
 | 18 | + | 
 | 19 | + ## Limit image size to prevent abuse  | 
 | 20 | + if ($width ~ "^[0-9]{4}$") { return 404; }  | 
 | 21 | + | 
 | 22 | + ## Cache headers  | 
 | 23 | + add_header X-Imgproxy-Cache $upstream_cache_status;  | 
 | 24 | + | 
 | 25 | + ## Proxy product images to imgproxy service  | 
 | 26 | + set $resize "rs:fit:$width:$height";  | 
 | 27 | + set $watermark "wm:0.3:soea:0:0:0.10";  | 
 | 28 | + set $image_path "plain/local:/$uri";  | 
 | 29 | + set $format "@webp";  | 
15 | 30 | 
 
  | 
16 |  | - if ($arg_width != '') {  | 
17 |  | - set $width $arg_width;  | 
 | 31 | + proxy_pass http://imgproxy/insecure/$resize/$watermark/$image_path$format;  | 
 | 32 | + | 
 | 33 | + ## Cache settings  | 
 | 34 | + proxy_cache imgproxy;  | 
 | 35 | + proxy_cache_key "$scheme$request_method$host$uri$width$height";  | 
 | 36 | + proxy_cache_valid 200 35d;  | 
 | 37 | + proxy_cache_valid 404 1h;  | 
 | 38 | + proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;  | 
 | 39 | + proxy_cache_background_update on;  | 
 | 40 | + proxy_cache_lock on;  | 
18 | 41 |  }  | 
19 |  | - if ($arg_height != '') {  | 
20 |  | - set $height $arg_height;  | 
 | 42 | + | 
 | 43 | + ## All other images (non-product) - css, js, etc from media.  | 
 | 44 | + location ~* \.(jpg|jpeg|png|webp|gif|svg|swf|eot|ttf|otf|woff|woff2|js|css|ico|txt)$ {  | 
 | 45 | + expires max;  | 
 | 46 | + add_header Cache-Control "public";  | 
 | 47 | + proxy_pass http://varnish;  | 
21 | 48 |  }  | 
 | 49 | + ## Default media handler for other files  | 
 | 50 | + proxy_pass http://varnish;  | 
 | 51 | +}  | 
22 | 52 | 
 
  | 
23 |  | - if ($width ~* "^[0-9]{4}$") { return 415; }  | 
24 |  | - | 
25 |  | - image_filter resize $width $height;  | 
26 |  | - image_filter_jpeg_quality 65;  | 
27 |  | - image_filter_webp_quality 65;  | 
28 |  | - image_filter_buffer 1M;  | 
29 |  | - | 
30 |  | - try_files $uri $uri/ @media;  | 
31 |  | - }  | 
32 |  | - | 
33 |  | - ## fonts  | 
34 |  | - location ~* \.(swf|eot|ttf|otf|woff|woff2|js|css|ico|txt)$ {  | 
35 |  | - expires max;  | 
36 |  | - add_header Cache-Control "public";  | 
37 |  | - try_files $uri $uri/ @media;  | 
38 |  | - }  | 
39 |  | - try_files $uri $uri/ @media;  | 
40 |  | - }  | 
41 |  | - | 
42 |  | -location @media { try_files $uri $uri/ /get.php$is_args$args; }  | 
43 | 53 | 
 
  | 
0 commit comments