memcache and proxy
Paul B
paul2791 at gmail.com
Wed Sep 3 18:23:50 MSD 2008
I am using nginx as the front end for our website, proxying PHP requests off to
another server.
I want to make sure nginx catches 502 and 504 errors (incase the php backend is
down) and redirect these errors to a static page.
So i have this working fine
#serve static pages with nginx
location ~* ^.+\.(swf|xml|png|html|jpg|jpeg|gif|pdf|ico|css|js)$ {
root /data/htdocs/;
}
#proxy the rest to backend
location / {
index index.php ;
error_page 504 = /index.html;
error_page 502 = /index.html;
proxy_pass http://10.100.250.100:88;
}
If my backend is working, site works fine, if i shut down the php server i get
the index.html page. Works like a charm.
However, I want to also use memcache, so that some php pages can get served from
cache and not have to be sent to the backend
so i change this to my conf
location / {
index index.php ;
set $memcached_key "guest:Action:$uri";
memcached_pass 10.100.250.101:11220;
default_type text/html;
error_page 404 = /fallback;
}
location = /fallback {
proxy_pass http://10.100.250.100:88;
error_page 502 = /index.html;
error_page 504 = /index.html;
}
When my backend server is up, this too works fine. I can store pages in cache
and they get displayed and if the page isnt in cache, the backed will serve it
up. However, if i shutdown my backend server, the 502 and 504 redirects no
longer work. I see the 502 Bad Gateway nginx/0.6.32 error page. Nothing i do
seems to fix this. As soon as i add the fallback location for memcache, i can no
longer catch the 502 or 504 errors.
any idea how to fix this???
More information about the nginx
mailing list