How to setup Proxy Cache with Nginx and Passenger

Posted by tiny on Server Fault See other posts from Server Fault or by tiny
Published on 2011-01-14T03:27:39Z Indexed on 2011/01/14 3:55 UTC
Read the original article Hit count: 183

Filed under:
|
|

I use Nginx and Passenger for my rails application. I want to use proxy cache to cache my pages. However, every request go direct to my rails application. I don't know what wrong with my configuration. Below is my configuration:

user www-data;
worker_processes  1;


events {
    worker_connections  1024;
}

http {
    passenger_root /usr/lib/ruby/gems/1.8/gems/passenger-2.2.15;
    passenger_ruby /usr/bin/ruby1.8;
    passenger_max_pool_size 6;
    passenger_max_instances_per_app 1;
    passenger_pool_idle_time 0;
    rails_spawn_method conservative;
    include       mime.types;
    default_type  application/octet-stream;

    server_names_hash_bucket_size 512;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;
    tcp_nodelay        on;

    gzip  on;
    gzip_http_version 1.0;
    gzip_vary on;
    gzip_comp_level 6;
    gzip_proxied any;
    gzip_types text/plain text/css text/javascript application/javascript    application/json application/x-javascript text/xml application/xml application/xml+rss;

    proxy_cache_path  /var/www/cache/webapp levels=1:2 keys_zone=webapp:8m max_size=1000m inactive=600m;
    include vhosts/*.conf;

    include /opt/nginx/conf/sites-enabled/*;

    root    /var/www;
}


server {
    listen 127.0.0.1:3008;
    server_name localhost;
    root /var/www/yoolk_web_app/public;   # <--- be sure to point to 'public'!
    passenger_enabled on;
    rails_env development;
    passenger_use_global_queue on;

}

server {
    listen 80;
    server_name webpage.dev;
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header  Host       $host;

    error_page 503 http://$host/maintenance.html;

    location ~* (css|js|png|jpe?g|gif|ico)$ {
    root /var/www/web_app/public;
    expires       max;
}

location / {
    proxy_pass http://127.0.0.1:3008/;
    proxy_cache webapp;
    proxy_cache_valid  200 10m;
}

#More Location

}

© Server Fault or respective owner

Related posts about nginx

Related posts about passenger