# Passenger with nginx not caching properly (cross post from passenger google group)

**URL:** <https://www.ruby-forum.com/t/passenger-with-nginx-not-caching-properly-cross-post-from-passenger-google-group/202753>\
**Category:** Deployment\
**Created:** [February 5, 2011, 12:48am UTC](https://www.ruby-forum.com/t/passenger-with-nginx-not-caching-properly-cross-post-from-passenger-google-group/202753 "2011-02-05T00:48:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [February 5, 2011, 12:48am UTC](https://www.ruby-forum.com/t/passenger-with-nginx-not-caching-properly-cross-post-from-passenger-google-group/202753/1 "2011-02-05T00:48:46Z")

</div>

I’ve got latest passenger running with nginx with conf:

pid /opt/nginx/logs/nginx.pid;

# Run as the nginx user

user root;  
worker\_processes 2;

error\_log /opt/nginx/logs/error.log notice;

events {  
worker\_connections 1024;  
use epoll;  
}

http {  
server\_names\_hash\_bucket\_size 64;

# More Linux performance awesomeness

tcp\_nopush on;  
tcp\_nodelay off;

# Where to store the body of large client requests on disk

# NGINX will stream this to disk before posting it to your Mongrels,

# preventing slow clients tying up your app.

client\_body\_temp\_path /var/spool/nginx-client-body 1 2;

# Max size of a request from a client (usually a POST). This will

limit

# the size of file uploads to your app

client\_body\_buffer\_size 8k;  
client\_header\_buffer\_size 1k;  
client\_max\_body\_size 1k;  
large\_client\_header\_buffers 4 8k;

## Timeouts

client\_body\_timeout 5;  
client\_header\_timeout 5;  
keepalive\_timeout 5 5;  
send\_timeout 5;

## General Options

ignore\_invalid\_headers on;  
limit\_zone carboncal $binary\_remote\_addr 1m;  
recursive\_error\_pages on;  
sendfile on;  
server\_name\_in\_redirect off;  
server\_tokens off;

# passenger loading stuff

passenger\_root  
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/passenger-3.0.2;  
passenger\_ruby /usr/local/rvm/wrappers/ruby-1.9.2-p136/ruby;

include /opt/nginx/conf/mime.types;  
default\_type application/octet-stream;

## Compression

gzip on;  
gzip\_buffers 16 8k;  
#compression level between 1 and 9  
gzip\_comp\_level 9;  
gzip\_http\_version 1.0;  
gzip\_min\_length 0;  
gzip\_types text/plain text/html text/css image/x-icon image/bmp  
application/x-javascript text/xml application/xml application/xml+rss  
text/javascript ;  
gzip\_vary on;  
gzip\_proxied any;

# Some version of IE 6 don’t handle compression well on some

mime-types, so just disable them  
gzip\_disable “MSIE [1-6].(?!.\*SV1)”;

# Send along useful info to the mongrels

proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header Host $http\_host;  
proxy\_redirect off;  
proxy\_max\_temp\_file\_size 0;

## Log Format

log\_format main '$remote\_addr $host $remote\_user [$time\_local]  
“$request” ’  
‘$status $body\_bytes\_sent “$http\_referer”  
“$http\_user\_agent” “$gzip\_ratio”’;

access\_log /opt/nginx/logs/access.log main;

# virtual hosting

server {  
access\_log /opt/nginx/logs/test\_server.access.log main buffer=32k;  
error\_log /opt/nginx/logs/test\_server.error.log info;  
expires 6h;  
listen 80 default rcvbuf=64k backlog=128;  
root /opt/apps/website/public;  
server\_name website [www.website.com](http://www.website.com);  
passenger\_enabled on;  
}  
}

No matter what action I do, nginx seems to only render the cached page.  
I’ve to refresh the page to see new changes, i.e. when I click signout,  
I am still logged, but if I refresh the page its logs me out. I’m  
guessing the problem has to do with rewrites. I’ve tried the below and  
various others, but still nothing.

```
if (-f $document_root/cache/$uri/index.html) {
  rewrite (.*) /cache/$1/index.html break;
}

# pages like /about, cached with .html but accessed without
if (-f $document_root/cache/$uri.html) {
  rewrite (.*) /cache/$1.html break;
}

# pages like /api/v1/something.xml, cached as xml
if (-f $document_root/cache/$uri) {
  rewrite (.*) /cache/$1 break;
}

```

---

<div class="post-metadata">

**Author:** ![senthilnayagam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecb155/32.png) [@senthilnayagam](https://www.ruby-forum.com/u/senthilnayagam)\
**Post date:** [February 6, 2011, 7:52am UTC](https://www.ruby-forum.com/t/passenger-with-nginx-not-caching-properly-cross-post-from-passenger-google-group/202753/2 "2011-02-06T07:52:09Z")

</div>

Turns out its the damn expires 6h line that’s causing the trouble.
