Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use image proxy for images #5

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions kubernetes/configmap/nginx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,20 @@ data:
try_files $uri @app;
}

location ~ ^\/content\/images\/(?<entity_name>\w+)(?<image_type>\/\w+)?\/(?<image_size>\w+)\/(?<add_image_id>\d+--)?[\w\-]+_(?<image_id>\d+)\.(?<image_extension>jpg|jpeg|png|gif) {
location ~ ^\/content\/images\/(?<entity_name>\w+)(?<image_type>\/\w+)?\/(?<image_size>(default|original|galleryThumbnail|modal|list|thumbnail|thumbnailSmall|thumbnailExtraSmall|thumbnailMedium|header|footer|productList|productListSecondRow|cartPreview|productListMiddle|productListMiddleRetina|listAside|listGrid|searchThumbnail|listBig)\/)(?<add_image_id>\d+--)?(?<image_name>[\w\-]+_(?<image_id>\d+))\.(?<image_extension>jpg|jpeg|png|gif) {
expires 1w;
return 301 $scheme://$http_host/content/images/$entity_name$image_type/$image_name.$image_extension$is_args$args;
}

location ~ ^\/content\/images\/(?<entity_name>\w+)(?<image_type>\/\w+)?\/(?<image_name>[\w\-]+_(?<image_id>\d+))\.(?<image_extension>jpg|jpeg|png|gif) {
expires 1w;

error_page 418 = @imageResizer;

if ($is_args != '') {
return 418;
}

# VSHosting DNS
resolver 78.24.12.150;
proxy_intercept_errors on;
Expand All @@ -134,13 +146,7 @@ data:
proxy_set_header Authorization "";
proxy_buffering off;

proxy_cache cache;
proxy_cache_revalidate on;
proxy_cache_min_uses 3;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
proxy_cache_background_update on;
proxy_cache_lock on;
proxy_pass {{S3_ENDPOINT}}/{{PROJECT_NAME}}/web/content/images/$entity_name$image_type/$image_size/$add_image_id$image_id.$image_extension;
proxy_pass {{S3_ENDPOINT}}/{{PROJECT_NAME}}/web/content/images/$entity_name$image_type/$image_id.$image_extension;
}

location ~ ^/content/ {
Expand All @@ -162,6 +168,12 @@ data:
# so it is safer to cache generated images only for few days.
expires 1w;

error_page 418 = @imageResizer;

if ($is_args != '') {
return 418;
}

# (try_files directive is not inherited from the parent location so we have to repeat it)
try_files $uri @app;
}
Expand Down Expand Up @@ -195,4 +207,10 @@ data:
fastcgi_param SCRIPT_FILENAME $realpath_root/index.php;
fastcgi_param HTTPS $http_x_forwarded_proto;
}

location @imageResizer {
fastcgi_pass php-upstream;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root/imageResizer.php;
}
}