Overriding individual websites hosted in NGINX to show a Maintenance Page
We have an architecture whereby we are hosting multiple sites in NGINX. Each NGINX site has its own config.Each of these sites points to a common codebase but points to a different domain name and its associated SSL.
What we want to do is during maintenance is to show a common Maintenance.html page once the request for the page is made. While, we can go into the website.conf file for each website and insert a rewrite rule, it is not a complete solution - its more of a hack which we are trying to avoid.
We would like to implement this in the nginx.conf file at the root level, whereby any request that comes in over (443) is to be intercepted (before its own config file is loaded) and redirected to a common Maintenance.html page.
How can this achieved at the nginx.conf file level?
Thanks
Solution 1:
You can do one time edit of all hosts (and don't forget to edit a template from which these are created) and after that you'll never need to edit them all.
You create an empty file, which you can call, for example, "all_vhosts_override". You add include "all_vhosts_override";
near the top of each vhost definition, above all location
and alias
entries.
When you need to override something in all vhosts at once, you add statements into that file and reload nginx. All vhosts will receive config from this single file, you wouldn't need to update their individual configs. Just clear override file empty when you done your maintenance and reload again.