Memcache and proxy

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???

Hello!

On Wed, Sep 03, 2008 at 02:23:50PM +0000, Paul B wrote:

root /data/htdocs/;

set $memcached_key “guest:Action:$uri”;

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???

http://wiki.codemongers.com/NginxHttpCoreModule#recursive_error_pages

Maxim D.

Maxim D. <[email protected]…> writes:

http://wiki.codemongers.com/NginxHttpCoreModule#recursive_error_pages

Maxim D.

Excellent, I knew it would have a simple answer.
Hopefully there is an as simple fix to the next problem i have
again concerning memcache and proxy

I have a url
http://my.domain.com/something/one

i don’t cache it, so it passes it to the proxy.

What the page should do is a simple redirect to

http://my.domain.com/something/one/content

If i remove my memcache line, so that everything in location / goes to
proxy_pass http://backend;

it works
If i go direct to the proxy port, it works
However, using my memcache config, it passes it to my /fallback
locations and it
stops working. I get a blank page in my browser and it doesn’t redirect.
I can
check the logs of my backend, and I see exactly the same request either
way, it
is just that when i pass it to /fallback, the redirect does not seem to
get
passed back to nginx.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs