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"; } }