-
-
Save vmoravec/231bb4d627c1f9b11c502bff2d368b48 to your computer and use it in GitHub Desktop.
Nginx S3 Proxy with caching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
events { | |
worker_connections 1024; | |
} | |
http { | |
default_type text/html; | |
access_log /dev/stdout; | |
sendfile on; | |
keepalive_timeout 65; | |
proxy_cache_path /tmp/ levels=1:2 keys_zone=s3_cache:10m max_size=500m | |
inactive=60m use_temp_path=off; | |
server { | |
listen 8080; | |
location /s3/ { | |
proxy_http_version 1.1; | |
proxy_set_header Connection ""; | |
proxy_set_header Authorization ''; | |
proxy_set_header Host bucket.s3-eu-west-1.amazonaws.com; | |
proxy_hide_header x-amz-id-2; | |
proxy_hide_header x-amz-request-id; | |
proxy_hide_header x-amz-meta-server-side-encryption; | |
proxy_hide_header x-amz-server-side-encryption; | |
proxy_hide_header Set-Cookie; | |
proxy_ignore_headers Set-Cookie; | |
proxy_intercept_errors on; | |
add_header Cache-Control max-age=31536000; | |
proxy_pass http://bucket.s3-eu-west-1.amazonaws.com/; | |
} | |
location /s3_cached/ { | |
proxy_http_version 1.1; | |
proxy_set_header Connection ""; | |
proxy_set_header Authorization ''; | |
proxy_set_header Host bucket.s3-eu-west-1.amazonaws.com; | |
proxy_hide_header x-amz-id-2; | |
proxy_hide_header x-amz-request-id; | |
proxy_hide_header x-amz-meta-server-side-encryption; | |
proxy_hide_header x-amz-server-side-encryption; | |
proxy_hide_header Set-Cookie; | |
proxy_ignore_headers Set-Cookie; | |
proxy_cache_revalidate on; | |
proxy_intercept_errors on; | |
proxy_pass http://bucket.s3-eu-west-1.amazonaws.com/; | |
proxy_cache s3_cache; | |
proxy_cache_valid 200 24h; | |
proxy_cache_valid 403 15m; | |
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504; | |
proxy_cache_lock on; | |
proxy_cache_bypass $http_cache_purge; | |
add_header Cache-Control max-age=31536000; | |
add_header X-Cache-Status $upstream_cache_status; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment