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

Iain Barnett iainspeed at
Mon Jun 6 16:50:42 MSD 2011


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:, server: hercules, request: "GET /download/e2a25db11bdbdd783531783eaa16eafdfc86355b/1307089096/file.m4a/ HTTP/1.1", upstream: "", host: "fakehost.blob", referrer: "http://fakehost.blob/music/file.m4a"

Here is the Nginx config from sites-available:

upstream fakehost.blob {

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 {
    alias /Users/www/sites/$http_host/assets/files;
  location / {
    proxy_pass http://$http_host;
  location = /50x.html {
    root   html;

and in the main nginx.conf:

http {
  server_names_hash_bucket_size 64;
  include       mime.types;
  default_type  application/octet-stream;

  log_format    main  '$remote_addr - $remote_user [$time_local] $request '
                      '"$status" $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

  sendfile      on;

  keepalive_timeout  65;## General Options
  ignore_invalid_headers   on;
  server_name_in_redirect off;
  server_tokens           off;
  tcp_nopush          on;
  tcp_nodelay         off;
  ## Proxy options
  proxy_buffering           on;
  #proxy_cache_min_uses       3;
  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;

  proxy_connect_timeout      90;
  proxy_send_timeout         90;
  proxy_read_timeout         90;

  proxy_buffer_size          4k;
  proxy_buffers              4 32k;
  proxy_busy_buffers_size    64k;
  proxy_temp_file_write_size 64k;


If anyone is able to give me some insight or help with this I'd be very grateful, as I've reached the limit (I'm far beyond it!:) of my knowledge with Nginx.


More information about the nginx mailing list