Welcome! Log In Create A New Profile

Advanced

Re: Rails XSendfile via Nginx

Francis Daly
May 10, 2012 08:38PM
On Thu, May 10, 2012 at 10:46:41PM +0200, Ari King wrote:
> > or do you want your rails backend server to do some processing and
> > decide whether or not they should be sent the contents of that file,

> I want rails to authenticate/authorize access to the content in question
> and then have nginx serve that file. The following articles
> explain/demonstrate what I'm trying to do:
>
> http://rack.rubyforge.org/doc/Rack/Sendfile.html
>
> http://thedataasylum.com/articles/how-rails-nginx-x-accel-redirect-work-together.html

That seems pretty clear, and seems to match what was mentioned earlier
in the thread.

You must configure the nginx location that corresponds to "/public/url",
to send the request to rails.

You must configure the rails side to send back a response with
"X-Accel-Redirect: /private/url".

You must configure the nginx location that corresponds to "/private/url"
to serve the correct file.

It is probably simplest (and matches the examples on those two pages
most closely) if the /private/url that rails returns maps directly to
a file on the filesystem.

On the nginx side, you want two location{}s -- one which matches
/public/url and one which matches /private/url.

On the rails side, do whatever it takes to get it to turn /public/url
into /private/url. That will probably involve the alias mapping thing
you mentioned earlier -- but that's a rails thing, so you'll get better
help on a rails list for that.

Your thedataasylum.com link does seem to give a strong hint what it is
about, though -- in rails code you call send_file() with the actual
filename you wish to have sent, and then the X-Accel-Mapping value
replaces the first bit of that filename with the private url prefix.

It appears that what you have right now is the location that matches
/public/url not sending the request to rails. And you don't appear to
have any specific location matching the private url, which seems to be
of the form "/video/1/original/example_one.ogg".

So, probably, get rid of your "location /recipes/" thing, and add a
"location /video/" with a suitable alias or root directive.

If you're still having difficulties, I suggest you show your nginx config,
and show the curl request and response when you make the request of the
rails server directly, including "-i" for the headers, and five "-H"
arguments, one for each "proxy_set_header" value that you have in your
nginx config.

(And if that doesn't make it clear where the problem is, probably also
show the line in your rails code which does "send_file()". But that bit
will probably be more interesting to a rails list.)

Good luck with it,

f
--
Francis Daly francis@daoine.org

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Rails XSendfile via Nginx

Ari King May 07, 2012 06:54PM

Re: Rails XSendfile via Nginx

Jonathan Matthews May 07, 2012 07:18PM

Re: Rails XSendfile via Nginx

Jonathan Matthews May 07, 2012 07:22PM

Re: Rails XSendfile via Nginx

Ari King May 08, 2012 11:00PM

Re: Rails XSendfile via Nginx

Jonathan Matthews May 09, 2012 06:22AM

Re: Rails XSendfile via Nginx

Francis Daly May 09, 2012 07:26AM

Re: Rails XSendfile via Nginx

Ari King May 09, 2012 05:22PM

Re: Rails XSendfile via Nginx

Ari King May 09, 2012 06:18PM

Re: Rails XSendfile via Nginx

Francis Daly May 09, 2012 06:42PM

Re: Rails XSendfile via Nginx

Francis Daly May 09, 2012 06:40PM

Re: Rails XSendfile via Nginx

Ari King May 10, 2012 04:48PM

Re: Rails XSendfile via Nginx

Francis Daly May 10, 2012 08:38PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 311
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready