Rails XSendfile via Nginx

Francis Daly francis at daoine.org
Wed May 9 11:24:46 UTC 2012

On Wed, May 09, 2012 at 04:58:55AM +0200, Ari King wrote:
> Jonathan Matthews wrote in post #1059929:

Hi there,

> Prior to asking my original question, I checked my error.log and found
> no errors whatsoever. I also tried using curl, but the content returned
> is a Nginx 404 error page. Any other ideas? I also doubled checked my
> alias configuration; as per nginx docs, location & alias take regex
> expressions and captures. My hunch is that the url is the problem
> (/recipes/1/video) since it does NOT contain the filename.

your config has two location{} blocks:

location /
location /recipes/(.*)/video

Probably you want to include "~" in your second location directive:

That might be sufficient to get everything working for you.

It's not clear to me exactly how you wish things to work. If the above
change gets things working, then it doesn't matter that it's not clear
to me. But:

the usual way to use X-Accel-Redirect is that the client accesses
"/public/uri" which nginx sends to an upstream for processing; that
upstream returns X-Accel-Redirect to "/private/uri"; and nginx is
configured to serve "/private/uri" from the filesystem.

So: if the client wishes to get access to the file "test.video", what
public url will they use to access it? What is the X-Accel-Redirect
header that the backend sends to nginx? And where on the filesystem is
the file "test.video"? If you can answer those questions, then it may
become clear how nginx should be configured to allow it all to happen.

Francis Daly        francis at daoine.org

More information about the nginx mailing list