-
-
Save vmoravec/6de664fc892e221cfd3638b02b2b2c65 to your computer and use it in GitHub Desktop.
Simple Nginx Proxy to S3 Bucket Asset
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
server { | |
listen 80; | |
listen 443 default_server ssl; | |
ssl on; | |
ssl_certificate /etc/ssl/certs/myssl.crt; | |
ssl_certificate_key /etc/ssl/private/myssl.key; | |
server_name *.example.com; | |
root /var/www/vhosts/website; | |
location / { | |
index index.php index.html index.htm; | |
if (-f $request_filename) { | |
break; | |
} | |
if (-d $request_filename) { | |
break; | |
} | |
# using PHP app routing | |
rewrite ^(.+)$ /index.php?url=$1 last; | |
} | |
# Proxy any URL request to S3 bucket and remove any Amazon headers | |
location ~ "^/asset/(.*)$" { | |
add_header X-Asset-Location $hostname; | |
set $bucket "<BUCKET-NAME>"; | |
set $key $1; | |
rewrite .* /$key break; | |
# no client headers | |
proxy_pass_request_headers off; | |
# let amazon take the buffering load | |
proxy_buffering off; | |
# let amazon retry a few times if first timeouts are 5xx response | |
proxy_next_upstream error timeout http_500 http_502 http_503 http_504; | |
proxy_set_header Host $bucket.s3.amazonaws.com; | |
proxy_pass http://s3.amazonaws.com; | |
proxy_hide_header "x-amz-id-2"; | |
proxy_hide_header "x-amz-request-id"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment