Rails 3 passenger nginx send_file with x accel redirect and x accel mapping

After a lot of searching as to why range headers were not working despite thinking that I had X-Accel-Redirect configured properly, I realized that I was missing something in my nginx config and so send_file was still sending via rails rather than nginx, causing range headers to fail.

In order to fix this, I had to add a bit more to my nginx config:

1
2
3
4
5
6
7
8
9
10
11
12
13
server {
listen 80;
server_name example.com;
root /home/keyvan/example_app/public;
passenger_enabled on;
passenger_set_cgi_param HTTP_X_ACCEL_MAPPING /=/sec/;
passenger_pass_header X-Accel-Redirect;

location /sec/ {
alias /;
internal;
}
}

Now it works!


http://stackoverflow.com/questions/6237016/message-x-accel-mapping-header-missing-in-nginx-error-log http://airbladesoftware.com/notes/rails-nginx-x-accel-mapping