nginx – How to Make Nginx Always Return HTTP 503

503-errorhaproxynginx

I am using HAproxy in front of an app that is on multiple other servers. I would like to set up a vhost in a local nginx instance that only serves a 503 for every request (to use as the 'backup' server when all backends are down). I know how to set the custom error page (as in How can I make Nginx return HTTP 503 when my proxied app server is down?) but how I can make it so that every request to nginx returns a 503?

Best Answer

This doesn't work?

location / {
  return 503;
}

There might be some tricks you have to use to get assets to show up on your custom error page (i.e., say your 503.html has an image in it. You have to do some logic to make the image show up with a 200 code, otherwise it'll be missing with a 503).