Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0563f06

Browse files
committed
fix: Adjust config for docker
- imgproxy optimization
1 parent 71c45c5 commit 0563f06

File tree

3 files changed

+58
-55
lines changed

3 files changed

+58
-55
lines changed

‎magento2/conf_m2/media.conf‎

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,53 @@
1-
21
## Media location
32
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";
1530

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;
1841
}
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;
2148
}
49+
## Default media handler for other files
50+
proxy_pass http://varnish;
51+
}
2252

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; }
4353

‎magento2/nginx.conf‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ worker_rlimit_nofile 100000;
44

55
pcre_jit on;
66

7-
## Load Dynamic Modules ##
8-
load_module modules/ngx_http_image_filter_module.so;
9-
107
pid /var/run/nginx.pid;
118

129
events {
@@ -60,8 +57,8 @@ http {
6057
proxy_set_header X-Forwarded-Port 443;
6158
proxy_set_header X-Secure on;
6259

63-
# Microcache
64-
#proxy_cache_path /tmp/nginx levels=1:2 keys_zone=microcache:100M max_size=500M inactive=2h;
60+
## Imgproxy cache
61+
proxy_cache_path /var/cache/nginx/imgproxy levels=1:2 keys_zone=imgproxy:100m max_size=10g inactive=30d use_temp_path=off;
6562

6663
## Flood protection example (see conf_m2/extra_protect.conf)
6764
limit_req_zone $binary_remote_addr zone=checkout:35m rate=1r/s;
@@ -132,7 +129,8 @@ http {
132129

133130
upstream varnish { server varnish:8081; }
134131
upstream nginx { server nginx:8080; }
135-
upstream rabbitmq { server rabbitmq:15672; }
132+
upstream rabbitmq { server rabbitmq:15672; }
133+
upstream imgproxy { server imgproxy:4593; }
136134

137135
## Main domain configuration
138136
include /etc/nginx/sites-enabled/*.conf;

‎magento2/sites-available/magento2.conf‎

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@
3333
gzip_types application/javascript application/x-javascript application/rss+xml text/javascript text/css text/plain image/x-icon image/svg+xml;
3434
gzip_buffers 4 16k;
3535
gzip_comp_level 6;
36-
37-
# Brotli compression alternative to Gzip
38-
#brotli on;
39-
#brotli_types text/xml image/svg+xml application/x-font-ttf image/vnd.microsoft.icon application/x-font-opentype application/json font/eot application/vnd.ms-fontobject application/javascript font/otf application/xml application/xhtml+xml text/javascript application/x-javascript text/plain application/x-font-truetype application/xml+rss image/x-icon font/opentype text/css image/x-win-bitmap;
40-
#brotli_comp_level 8;
4136

4237
if ($deny_ip) { return 403; }
4338
if ($bad_user_agent) { return 403; }
@@ -49,19 +44,22 @@
4944
include conf_m2/admin_protect.conf;
5045

5146
## Error log/page
52-
#include conf_m2/error_page.conf;
47+
# include conf_m2/error_page.conf;
5348

5449
## sitemap and feeds?
55-
include conf_m2/sitemap.conf;
50+
include conf_m2/sitemap.conf;
5651

5752
## phpMyAdmin configuration
58-
include conf_m2/phpmyadmin.conf;
53+
include conf_m2/phpmyadmin.conf;
5954

6055
## Server maintenance block.
61-
include conf_m2/maintenance.conf;
56+
include conf_m2/maintenance.conf;
6257

6358
## Static files push only
64-
include conf_m2/static.conf;
59+
include conf_m2/static.conf;
60+
61+
## Product images and all media/ files
62+
include conf_m2/media.conf;
6563

6664
## Proxy-pass to Varnish
6765
location / { proxy_pass http://varnish; }
@@ -85,9 +83,6 @@
8583
location / {
8684
try_files $uri $uri/ /index.php$is_args$args;
8785
}
88-
89-
## Product images and all media/ files
90-
include conf_m2/media.conf;
9186

9287
## Process php files (strict rule, define files to be executed)
9388
location ~ ^/(index|health_check|get|static|errors/(report|404|503))\.php$ {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /