Help with X-Accel-Redirect and "rewrite or internal redirection cycle" errors

António P. P. Almeida appa at perusio.net
Mon Jun 6 17:14:47 MSD 2011


On 6 Jun 2011 13h50 WEST, iainspeed at gmail.com wrote:

> Hi,
>
> I'm trying to use X-Accel-Redirect from a Ruby app to hand over
> downloading of a file to Nginx, but it fails and the error in the
> logs is:
>
> 2011/06/03 09:18:16 [error] 20500#0: *37 rewrite or internal
> redirection cycle while internal redirect to "/files/file.m4a" while
> reading response header from upstream, client: 10.0.1.23, server:
> hercules, request: "GET
> /download/e2a25db11bdbdd783531783eaa16eafdfc86355b/1307089096/file.m4a/
> HTTP/1.1", upstream:
> "http://127.0.0.1:8679/download/e2a25db11bdbdd783531783eaa16eafdfc86355b/1307089096/file.m4a/",
> host: "fakehost.blob", referrer:
> "http://fakehost.blob/music/file.m4a"
>
>
> Here is the Nginx config from sites-available:
>
>
> upstream fakehost.blob {
> server 127.0.0.1:8679;
> server 127.0.0.1:8680;
> }
>
> server {
> listen  80;
>
> server_name fakehost.blob;
>
> access_log      /var/log/nginx/fakehost.blob.log main;
> error_log      /var/log/nginx/fakehost.blob.error.log info;
>
>
> location /files {
> internal;
> alias /Users/www/sites/$http_host/assets/files;
> }
>
> location / {
> proxy_pass http://$http_host;
> }
>
> location = /50x.html {
> root   html;
> }
> }

Problably your app is issuing redirects for that request. You should
issue the X-Accel-Redirect header with the the download location. 

X-Accel-Redirect path/to/download/file 

Only then will the Ruby handling of the file will be overriden and the
download handled by Nginx. Cf. http://wiki.nginx.org/NginxXSendfile

--- appa




More information about the nginx mailing list