Nginx proxy to s3 bucket gets 400 Invalid Argument
- by elssar
I have a Django app in which I serve media files through an nginx proxy to s3.
The relevant python code
response = HttpResponse()
response['X-Accel-Redirect'] = '/s3_redirect/%s' % filefield.url.replace('http://', '')
response['Content-Disposition'] = 'attachment; filename=%s' % filefield.name
return response
The nginx block for the internal redirect is
location ~* ^/s3_redirect/(.*) {
internal;
set $full_url http://$1;
proxy_pass $full_url;
And the request logged by s3 is.
REST.GET.OBJECT <media file> "GET <media file>" 400 InvalidArgument 354 - 4 -
"http://<referer>" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3)
AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1" -
I, for the life of me, can't figure out what's wrong. The url send to nginx by the app is valid, it works in the browser. And nginx is sending a request to s3.