dragonfly behind nginx/passenger with caching proxy

607 views
Skip to first unread message

Alex P.

unread,
Jun 14, 2011, 11:47:24 PM6/14/11
to Dragonfly
Hi!

Since I didn't find anywhere in documentation example how to put
dragonfly behind non rack-cache caching proxy, here is my example. It
works for me, may be useful for somebody else. Any comments would be
appreciated.

-----
config/initializers/dragonfly.rb:
-----
require 'dragonfly'
require 'uri'

### The dragonfly app ###
app = Dragonfly[:images]
app.configure_with(:rails)
app.configure_with(:imagemagick)

### Extend active record ###
if defined?(ActiveRecord::Base)
app.define_macro(ActiveRecord::Base, :image_accessor)
app.define_macro(ActiveRecord::Base, :file_accessor)
end

### Insert the middleware ###
Rails.application.middleware.insert 0,
'Dragonfly::Middleware', :images

-----
nginx.conf fragment
-----
http {
passenger_root /usr/local/lib/ruby/gems/1.9.1/gems/
passenger-3.0.7;
passenger_ruby /usr/local/bin/ruby;

server {
listen 127.0.0.1:8080;
server_name localhost;

root /YOUR_APP/public;
passenger_enabled on;
}

proxy_cache_path /opt/nginx/cache/dragonfly levels=2:2
keys_zone=dragonfly:100m inactive=30d max_size=1g;

server {
listen 80;
server_name YOUR_DOMAIN;

location / {
proxy_pass http://127.0.0.1:8080;
}

location /media {
proxy_pass http://127.0.0.1:8080;
proxy_cache dragonfly;
proxy_cache_valid 200 30d;
}
}
}

Regards, Alex.

elfassy

unread,
Sep 24, 2014, 9:36:28 AM9/24/14
to dragonf...@googlegroups.com, pis...@gmail.com
Anyone have an example like this with nginx + Unicorn? Thanks!
Reply all
Reply to author
Forward
0 new messages