How do i use X-Accel-Redirect with nginx
I have a asp.net website and i have nice urls so the user may see /abc/1/a.jpg
the path is docroot/abc/number/number/id.jpg
I need asp.net to decode where the real path is. So essentially i do it and instead of rewriting i set the X-Accel-Redirect header and called Reponse.End(); I got a 404 error. This code was in Application_BeginRequest. I tried not doing .End() and just return. I get a asp.net like 404 error. I messed around and gave up so instead of sending the header i called HttpContext.Current.RewritePath to the exact same path. The ima开发者_开发技巧ge now displays but its being handled by asp.net instead of nginx.
How do i get nginx to listen to my X-Accel-Redirect headers? What do i need in my config file? my current one looks like this
Note that i am in fact putting everything through asp.net.
server {
server_name www.MYSITE.com static.MYSITE.com;
root /var/www/MYSITE;
location / {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
gah. The problem was nginx config file. I needed to add
location /base/path {
internal;
}
The file must be in a directory/location that is marked internal;
I notice the content type is incorrect unless set to "". Heres what i did and i am not sure you need the first line
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ContentType = "";
HttpContext.Current.Response.AddHeader("X-Accel-Redirect", full);
HttpContext.Current.Response.End();
精彩评论