0

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.

elssar
  • 113
  • 9

1 Answers1

0

I guess the problem was in my nginx conf. Needed to add some more configuration. Following this blog post helped.

Added these lines to my nginx conf

  proxy_http_version     1.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_ignore_headers   "Set-Cookie";
  proxy_buffering        off;
  proxy_intercept_errors on;
elssar
  • 113
  • 9