Here’s one I struggled with a bit while upgrading lincolnloop.com yesterday.
Scenario: You need to take your site offline and want to redirect all its traffic to a “down for maintenance” page. For search engine friendliness, that page should return a 503: Service Unavailable status code. Here’s the (not entirely intuitive) way to do that in Nginx:
Now whenever you need to take your site offline, simply create the file maintenance.html
in the $document_root
(in our case, /var/www/mysite.com
). If the file exists, Nginx will serve it with a 503 status code, if not, it will proceed as usual.