Rails XSendfile via Nginx

Jonathan Matthews contact at jpluscplusm.com
Wed May 9 10:20:38 UTC 2012


On 9 May 2012 03:58, Ari King <lists at ruby-forum.com> wrote:
> 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.

Yes, that's what I meant about your use of "alias" being screwy. You
haven't indicated that you've tried hitting the app *directly*,
without nginx in the way, and examining the headers. This is always
really useful. In this case, however, I think the fault lies
elsewhere.

Here's what you've got in your config:
------------------------
location /recipes/(.*)/video {
      alias /var/www/app/current/uploads/videos/$1/original/;
}
------------------------

To me, this looks like when you request

  http://foo.bar.com/recipes/123/video

you're asking nginx to serve the "file"

  /var/www/app/current/uploads/videos/123/original/

But this isn't a file, it's a directory. So
http://wiki.nginx.org/HttpIndexModule#index kicks in and (unless
you've changed it) tries to serve
/var/www/app/current/uploads/videos/123/original/index.html.
Hence the 404.

I think your taxonomy is a bit fucked here, TBH, and you're reaping
the rewards of trying to implement the wrong public-facing data
structure.
If you have the scope to change it, I'd be going with something where
(a) "video" is on the left of the video ID and possibly (b) where
/recipes/ is out of the picture all together. Something like

http://foo.bar.com/video/123 or, if you anticipate getting to any scale
http://foo.bar.com/video/000/1/123 or, if "recipe" is still important
http://foo.bar.com/video/recipes/123 to allow you to have non-recipe
based videos in the future.

... and where the *file* on disk is named according to the ID - not
where the ID is just part of the filesystem path leading up to the
video.

HTH,
Jonathan
-- 
Jonathan Matthews
Oxford, London, UK
http://www.jpluscplusm.com/contact.html



More information about the nginx mailing list