The complete nginx solution to sending flowers and files with rails

Rails send_file is effed. It may send you flowers and whisper sweet nothingsblythedoll into your ear, but believe me, it will steal your memory, your lover and your freetime. If you are using apache or lighttpd, all the cool kids are using the x_send_file plugin. Nginx fans, check out my monkey patch so you too can send files, flowers and love without crashing mongrels with nginx’s equivalent X-Accel-Redirect header.

1. Install the x_send_file plugin.

ruby script/plugin install http://john.guen.in/svn/plugins/x_send_file

2. Copy monkey patch to

Replace vendor/plugins/x_send_file/lib/x_send_file/controller.rb with http://www.acidlunchbox.com/blythe/rails/x_send_file/controller.rb

3. Configure things

nginx.conf

remember to also add to server section if sending over ssl

location /files {

root /data/spongecell;

internal;

}

environment.rb

#send files through nginx

XSendFile::Plugin.options.update(

:header => ‘X-Accel-Redirect’,

:root => ‘/data/spongecell’,

:file_paths => ‘/data/spongecell/files’

)

In this example, x_send_file will create the following response header

>> x_send_file ‘/data/spongecell/files/snow/iheartbigdumps.jpg’

>> response.headers[‘X-Accel-Redirect’]

=> ‘/files/snow/iheartbigdumps.jpg’

 

Other resources:

Nginx X-Accel-Redirect

Nginx X-Accel-Redirect with rails and php examples

 

 

 

About these ads

5 Responses to The complete nginx solution to sending flowers and files with rails

  1. […] integration with  Nginx X-Accel-Redirect (and Apache’s X-SendFile) to tell your web server to send the cached file […]

  2. […] The complete nginx solution to sending flowers and files with rails […]

  3. Matthew says:

    Hi there Dear, are you really visiting this web site daily, if so afterward you will definitely get nice knowledge.

  4. […] with Apache, and hints that it can also be done with ngninx – but no examples. This post and this post show how to do it using the a plugin that apparently Rails 2.3 makes uncessary. This post suggests […]

  5. […] and hints that it can also be finished with ngninx – though no examples. This post and this post arrangement how to do it controlling a a plugin that apparently Rails 2.3 creates uncessary. This […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: