Skip to content

Commit 4322fea

Browse files
committed
Add more config
1 parent 862877a commit 4322fea

File tree

2 files changed

+78
-8
lines changed

2 files changed

+78
-8
lines changed

README.md

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Magento2 Custom Image Url
22

3-
Magento 2.4 has the option to set a dynamic URL (General -> Web -> Url options). This module adds an extra option to define the format of the URL.
4-
3+
Magento 2.4 has the option to set a dynamic URL (General -> Web -> Url options).
4+
This module adds an extra option to define the format of the URL.
55

66
## Install
77

@@ -13,17 +13,49 @@ php bin/magento setup:upgrade
1313

1414
## Configuration
1515

16-
You can configure the url in Web -> URLS
16+
You can configure the url in General -> Web -> Url Options. Set the 'Catalog media URL format' option to 'Image optimization based on query parameters'.
17+
This will prevent Magento from creating resized images. Select a Custom URL format for Imgproxy or Pattern, to use this module.
18+
19+
![image](https://user-images.githubusercontent.com/973269/108608605-6cbe5b00-73c8-11eb-90dd-37777dc5d64c.png)
20+
21+
22+
### Pattern
23+
24+
Provide a pattern to replace the URL with:
25+
26+
Example https://example.com/{{path}}?w={{width}}&h={{height}}
27+
28+
The available filters (for urlencode etc) and variables are described in the config.
29+
30+
### Imgproxy
31+
32+
![image](https://user-images.githubusercontent.com/973269/108608636-94152800-73c8-11eb-88bc-da2d6b4ed4c0.png)
33+
34+
35+
Use the Imgproxy format, either with URL, S3 or Local files. You can provide a key/hash to sign the URLs
36+
37+
This can be used with the AWS Remote storage: https://devdocs.magento.com/guides/v2.4/config-guide/remote-storage/config-remote-storage-aws-s3.html
38+
39+
You can provide the host and options. The format will be generated by the module.
40+
41+
Inscecure proxy to map the URL + Convert to Webp:
42+
43+
`docker run -p 8080:8080 -e IMGPROXY_ENFORCE_WEBP=1 darthsim/imgproxy`
44+
45+
Example Docker config to proxy with S3 + Signature
46+
47+
`docker run -p 8080:8080 -e IMGPROXY_USE_S3=1 -e AWS_ACCESS_KEY_ID=accesskey -e IMGPROXY_S3_REGION=eu-central-1 -e AWS_SECRET_ACCESS_KEY="secret" -e IMGPROXY_KEY=key -e IMGPROXY_SALT=salt darthsim/imgproxy`
48+
49+
See https://docs.imgproxy.net/ for more options.
50+
51+
See imgproxy-nginx-cached.conf for an example nginx proxy config with caching enabled.
1752

18-
## Possibible options
19-
- Pattern; describe the URL based on width/height/path etc
20-
- Imgproxy; provide an Imgproxy host with URL/Local/S3 options, including signature
21-
2253
## Todo / future ideas
2354

2455
- Other CDNs
2556
- ..
26-
57+
58+
2759
## License
2860

2961
MIT

imgproxy-nginx-cached.conf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Based on https://gist.github.com/DarthSim/ee75da7da21dc984fe5e99ac86509a9f
2+
3+
proxy_cache_path /var/www/cache levels=1:2 keys_zone=imgcache:10m max_size=1000m inactive=30d;
4+
proxy_temp_path /var/www/cache/tmp;
5+
6+
server {
7+
server_name your-domain.com;
8+
listen 443;
9+
10+
client_max_body_size 8M;
11+
12+
ssl on;
13+
ssl_certificate /path/to/your/cert.crt;
14+
ssl_certificate_key /path/to/your/cert.key;
15+
16+
keepalive_timeout 60;
17+
ssl_session_timeout 5m;
18+
19+
ssl_protocols TLSv1.2;
20+
ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS_AES_256_GCM_SHA384:TLS-AES-256-GCM-SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS-CHACHA20-POLY1305-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA;
21+
ssl_prefer_server_ciphers on;
22+
23+
location / {
24+
25+
proxy_cache imgcache;
26+
proxy_cache_valid 200 30d;
27+
proxy_cache_valid 404 1m;
28+
29+
if ($http_accept ~* "webp") {
30+
set $webp WEBP;
31+
}
32+
33+
proxy_cache_key $scheme$proxy_host$request_uri$webp;
34+
proxy_pass "http://127.0.0.1:8080";
35+
proxy_next_upstream error timeout invalid_header;
36+
proxy_redirect off;
37+
}
38+
}

0 commit comments

Comments
 (0)