title: NGINX: serve static file when proxy_pass fails
body: <p>I have a frontend running nginx which proxy requests to a backend running a web service.
  I would like to serve a static file if the backend service is down.</p>
  
  <p>Here is the configuration file I am using:</p>
  
  <pre><code>location ~ /api/admin {
          rewrite /xxxx/(.+) /$1 break;
          error_page 404 502 =200 /themes/yyyy/themes.json;
          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;
          add_header Access-Control-Allow-Credentials true;
          add_header Access-Control-Allow-Origin '*';
          add_header Access-Control-Allow-Methods 'GET, POST';
          proxy_intercept_errors on;
          proxy_pass http://xxxx;
  }
  
  location = /themes/yyyy/themes.json {
          rewrite /themes/yyyy/themes.json /api/admin/thematics/edito;
  }
  </code></pre>
  
  <p>when I call :</p>
  
  <pre><code>http://url/themes/geoportail/themes.json
  </code></pre>
  
  <p>I receive a 502 error from nginx, instead of 200 and the static file...</p>
  
  <pre><code>2014/08/25 17:02:35 [error] 13551#0: *6719 connect() failed (111: Connection refused) while connecting to upstream, client: 160.92.103.160, server: uri, request: "GET /themes/yyyy/themes.json HTTP/1.1", upstream: "http://IP:PORT/api/admin/thematics/edito", host: "", referrer: ""
  </code></pre>