title: When using NginX as a reverse proxy, how can i fallback to a maintenance url?
body: <p>I have setup Nginx in front of two IIS servers.  The main goal is to load balance, ssl offload, and cache static content. </p>
  
  <p>What i am having a really tough time with is showing a maintenance page when all the Upstream servers are either unavailable or throwing 404 errors.  I have created a maintenance.html file on my NginX box but cannot get it to load.  I can sometimes get it to load IIS 404s, and sometimes get it to load the default NginX 404.  What I am really trying to do is if for some reason all the upstreams are down or throwing 404s is to show the user a "Maintenance" page and eventually put in some code in that page to alert me that all the upstream servers have gone down. </p>
  
  <p>Here is my Configuration:</p>
  
  <pre><code># -------------------------------------------
  #       ACTUAL SITE WITH - SSL CERTIFICATE
  #------------------------------------------
  
  
  # Backend IIS Servers
  upstream backend-iis {
  
      # Health Checks
      #healthcheck_enabled; 
      #healthcheck_delay 5000; 
      #healthcheck_timeout 5000; 
      #healthcheck_failcount 1; 
  
      # Upstream Servers
          server ww1.pickle.com  max_fails=3  fail_timeout=31s;
          server ww2.pickle.com  max_fails=3  fail_timeout=31s;
          #server ww3.pickle.com;
  
        # Sticky Sessions
        #sticky;
        #ip_hash;
  
  }
  
  
  # Server Configuration
  server {
  
      # Server Specific Settings
         server_name        www.pickle.com;
         access_log         /var/log/nginx/www.pickle.com.log ;
         keepalive_timeout  5;
         allow              all;
         server_tokens      off; 
         gzip               on;
         gzip_vary          on;
  
      # SSL Settings (with SPDY 2)
         ssl on;
         listen 443 ssl spdy; 
         ssl_certificate /usr/share/nginx/ssl-certs/pickle_com/pickle_basic.crt;
      #  ssl_certificate /usr/share/nginx/ssl-certs/pickle_com/pickle_ev.crt;
         ssl_certificate_key        /usr/share/nginx/ssl-certs/pickle_com/pickle.com.key;
         ssl_session_timeout        15m;
         ssl_protocols              SSLv3 TLSv1 TLSv1.1 TLSv1.2;
         ssl_ciphers                RC4:HIGH:!aNULL:!MD5;
         ssl_prefer_server_ciphers  on;
         ssl_session_cache          shared:SSL:10m;
  
  
  
  
      # Proxy Pass to: backend-iis
      location / {
  
               #root               /usr/share/nginx/sites/pickle-down/;
  
           # Proxy Header to Keep Ip Address and Hostname
           proxy_redirect    off;
           proxy_set_header  Host              "www.pickle.com";
           proxy_set_header  X-Real-IP         $remote_addr;
           proxy_set_header  X-Forwarded-For   $proxy_add_x_forwarded_for;
           proxy_set_header  X-Forwarded-Proto $scheme;
  
           # Proxy Pass to Backend IIS Servers
           proxy_pass             http://backend-iis;
           # proxy_next_upstream    error timeout http_404;
           proxy_temp_path        /usr/share/nginx/temp;
  
           #Intercept Proxy Errors (show Nginx Error Pages)
           #proxy_intercept_errors on; 
                   error_page 404 500 502 503 504 = @maintenance;
  
      }
  
  
      # Proxy Pass to: backend-iis
      location @maintenance {
           internal;
           root        /usr/share/nginx/sites/pickle-down;
           index  maintenance.html index.html index.htm;
           allow all;
  
      }
  
  
  
     error_page 500 502 503 504 /50x.html;
     location = /50x.html {
     root html;
    }
  
     error_page 404 /404.html;
     location = /usr/share/nginx/sites/pickle-down/404.html {
     root html;
    }
  }
  </code></pre>