X-Accel-Redirect again, and again and again!

204 views
Skip to first unread message

Iain Barnett

unread,
Jun 3, 2011, 6:09:02 AM6/3/11
to sina...@googlegroups.com
Hi,

I managed to get Sinatra to pass file downloads over to Nginx using X-Accel-Redirect, and it works!

But only on my local server :( When I pushed it over to the deployment server and tested it there I get 500 errors from Nginx, so I changed the code a little to log it:

add = {'X-Accel-Redirect' => uri,
'Content-Type' => "audio/#{File.extname(title)[1..-1]}",
'Content-Disposition' => "attachment",
'Content-Transfer-Encoding' => 'application/octet-stream',
'Content-Length' => File.size( path_to_file ).to_s,
'Cache-Control' => 'no-cache',
'Content-Description' => 'File Transfer', }
options.logger.info "Going to send attachment #{add.inspect}"

headers( add )


Nginx complains with the error "...rewrite or internal redirection cycle while internal redirect to "/files/blahblah.m4a" while reading response header from upstream..."

The main thing I noticed in the Sinatra logs was that each attempt to download would produce 14 identical log messages, which explains Nginx complaining about a cycle:

I, [Fri 03-06-2011 1031 #20666] INFO -- : Going to send attachment {"X-Accel-Redirect"=>"/files/blahblah.m4a", "Content-Type"=>"audio/m4a", "Content-Disposition"=>"attachment", "Content-Transfer-Encoding"=>"application/octet-stream", "Content-Length"=>"9032392", "Cache-Control"=>"no-cache", "Content-Description"=>"File Transfer"}

Nginx.conf (relevant part)

location /files {
internal;
alias /Users/www/Sites/$http_host/assets/files;
}

location / {
proxy_pass http://$http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
}

The versions of Nginx(0.8.53), Ruby(1.9.2p0), Rack(1.3.0), Thin(1.2.11), and Sinatra(1.2.6) are identical on both machines. The Nginx confs are identical. The file paths logged are correct. Something must be different but I don't know what.

Would anyone have any advice on where I might look? I could really do with the help!

Any insight is much appreciated.

Regards,
Iain

PS I know that this could well be an Nginx error, but since (I reckon) more people on here are likely to have similar setups than on other lists, and I've got more control over Sinatra for debugging purposes, I thought this would be the best place to ask. And people on here have been very helpful to me so far :)

Reply all
Reply to author
Forward
0 new messages