# Mod\_proxy+mod\_cache - no upstream & set error\_page?

**URL:** <https://www.ruby-forum.com/t/mod-proxy-mod-cache-no-upstream-set-error-page/186815>\
**Category:** NGINX\
**Created:** [April 12, 2010, 8:46pm UTC](https://www.ruby-forum.com/t/mod-proxy-mod-cache-no-upstream-set-error-page/186815 "2010-04-12T20:46:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scott\_Smith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8797f3/32.png) [@Scott\_Smith](https://www.ruby-forum.com/u/Scott_Smith)\
**Post date:** [April 12, 2010, 8:46pm UTC](https://www.ruby-forum.com/t/mod-proxy-mod-cache-no-upstream-set-error-page/186815/1 "2010-04-12T20:46:16Z")

</div>

Hi,

I’m using Nginx with mod\_proxy+mod\_cache to proxy and cache specific  
pages.

When the upstream ($host) is down, and the page is not cached, Nginx  
returns a generic 502 page. Is it possible to use error\_page?

I’ve tried putting error\_page 502 directive in multiple places to no  
avail.

Here is my full config:

user daemon;  
worker\_processes 5;  
worker\_rlimit\_nofile 20480;

error\_log /var/log/nginx/error.log;  
pid /var/run/nginx.pid;

events {  
worker\_connections 4096;  
# multi\_accept on;  
use epoll;  
}

http {  
include /etc/nginx/mime.types;

```
 access_log /var/log/nginx/access.log;

 sendfile on;
 #tcp_nopush on;

 #keepalive_timeout 0;
 keepalive_timeout 65;
 tcp_nodelay on;

 gzip on;
 gzip_disable msie6;
 gzip_proxied any;

 proxy_cache_path /path/to/cache levels=1:1:2

```

keys\_zone=maint\_cache:512m inactive=15d max\_size=30g;  
proxy\_hide\_header Expires;  
proxy\_hide\_header Cache-Control;

```
 server {
     listen 80;
     server_name foo.bar.com;

     location /nginx_status {
         stub_status on;
         access_log off;
         allow 10.0.0.0/8;
         deny all;
     }

     root /path/to/htdocs;

     log_format cache_log '$time_local '
         '$upstream_cache_status '
         'Cache-Control: $upstream_http_cache_control '
         'Expires: $upstream_http_expires '
         '"$request" ($status) '
         '"$http_user_agent" ';

     access_log /var/log/nginx/proxy.access.log;
     access_log /var/log/nginx/proxy.cache.log cache_log;

     proxy_cache mycache;
     proxy_set_header Host $http_host;
     proxy_cache_use_stale error timeout updating http_500 http_502
         http_503 http_504 http_404;

     error_page 404 /default/index.html;

     if ($host ~* ^([a-z0-9\-]+\.([a-z]+))$) {
         set $host_with_www www.$1;
     }

     if ($host !~* ^([a-z0-9\-]+\.([a-z]+))$) {
         set $host_with_www $host;
     }

     location ~ /purge(/.*) {
         proxy_cache_purge mycache "$host_with_www$1";
         allow 10.0.0.0/8;
         deny all;
     }

     # The initial request MUST respond with HTTP 503.
     location ~ ^/$ {
         error_page 503 /503index;
         return 503;
     }

     location /503index {
         proxy_pass http://$host_with_www/path/to/index.php;
         proxy_cache_key "$host_with_www/index.php";
     }

     # If the CSS request isn't HTTP 200 some browsers don't render
     location /path/to/styles.css {
         proxy_pass http://$host_with_www/path/to/styles.css;
         proxy_cache_key "$host_with_www/styles.css";
     }

     location ~ /.*$ {
         error_page 503 /503index;
         return 503;
     }

```

}
