Nginx – How to make nginx reverse proxy let 503 error pages pass through to client

magentonginxreverse-proxy

I am running Magento (ecommerce PHP app) behind nginx as a reverse proxy to Apache which is running the PHP app. Static content is served directly by nginx. Magento has a "maintenance mode" which uses a 503 HTTP response. With my configuration when maintenance mode is enabled nginx returns a blank page with a 500 response instead of Magento's nice maintenance mode page with the 503 response. How can I make nginx let the 503 page pass through to the client?

Here is my nginx config:

upstream examplecluster       { server 1.2.3.4:80; }
server {
  listen       1.2.3.5:80;
  server_name  www.example.com;
  root         /var/www/example.com/www;

  # security
  location ~ (/(app/|includes/|lib/|pkginfo/|var/|report/config.xml|downloader/(pearlib|template|Maged)/)|/\.svn/|/\.ht.+) {
    return 404;
  }

  location ~ \.php$ {
    proxy_pass http://examplecluster;
    proxy_redirect default;
  }

  # static content
  location / {
    try_files $uri @apache;
    expires 7d;
  }

  # Apache
  location @apache {
    proxy_pass http://examplecluster;
    proxy_redirect default;
  }
}

Best Answer

Turns out there was truly an error while serving the 503 page so nginx was forwarding the response correctly afterall.

However, the relevant nginx setting is proxy_intercept_errors off; which is already the default..