From 83a5856627e77c4c79ab70ae7c1c363559f586ed Mon Sep 17 00:00:00 2001 From: r888888888 Date: Mon, 13 Mar 2017 16:26:07 -0700 Subject: [PATCH] include cache proxy config for nginx --- script/install/nginx.danbooru.conf | 35 ++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/script/install/nginx.danbooru.conf b/script/install/nginx.danbooru.conf index 8050c8ad5..88317b657 100644 --- a/script/install/nginx.danbooru.conf +++ b/script/install/nginx.danbooru.conf @@ -1,3 +1,5 @@ +proxy_cache_path /tmp/nginx-cache levels=1:2 keys_zone=STATIC:100m max_size=1000m inactive=24h use_temp_path=off; + server { listen 80; server_name __hostname__; @@ -23,11 +25,40 @@ server { if ($invalid_referer) { return 403; } - rewrite ^/data/sample/--.+?--(.+) /data/sample/$1 last; - rewrite ^/data/--.+?--(.+) /data/$1 last; + rewrite ^/data/sample/__.+?__(.+) /data/sample/$1 last; + rewrite ^/data/__.+?__(.+) /data/$1 last; expires max; break; } + + # to enable s3 proxy + location ~ ^/cached/data/(.+) { + rewrite ^/cached/data/sample/__.+?__(.+) /cached/data/sample/$1; + rewrite ^/cached/data/__.+?__(.+) /cached/data/$1; + if ($uri ~ "/cached/data/(.+)") { + set $s3_bucket 's3.amazonaws.com'; + set $url_full $1; + } + + proxy_set_header Host $s3_bucket; + proxy_set_header Authorization ''; + proxy_hide_header x-amz-id-2; + proxy_hide_header x-amz-request-id; + proxy_hide_header Set-Cookie; + + proxy_cache STATIC; + proxy_ignore_headers Set-Cookie Cache-Control X-Accel-Expires Expires; + proxy_cache_valid 200 48h; + proxy_cache_use_stale error timeout invalid_header updating http_500 http_5\ +02 http_503 http_504; + proxy_cache_key "$uri"; + proxy_cache_min_uses 2; + add_header X-Cache-Status $upstream_cache_status; + proxy_pass https://$s3_bucket/BUCKET_NAME/$url_full; + + break; + } + location /maintenance.html { expires 10; }