I've read a lot of questions about configuring nginx maintenance pages, but I can't figure out how to do this particular thing. Normally my nginx is just proxying everything to another service. For maintenance mode, I need it to return a maintenance.html page, but that page has images and css links. So the problem is if I 503 based on the existence of a file, it 503s all the images too. I can see how to avoid that without the proxy, but when not in maintenance mode, I need the images proxied too and I can't figure out how to do it. Essentially, I need this:
if maintenance mode if image or css -> send /var/www/html/image else -> send /var/www/html/maintenance.html else proxy everything including images and css end
The other answers I've read assume you want to always serve the images out of /var/www/html, but I only want to do that in maintenance mode. I've gotten this far, I just need to know how to handle the images.
error_page 503 @maintenance; location @maintenance { ### what goes here to prevent images from 503ing or returning maintenance.html rewrite ^(.*)$ /maintenance.html break; } location / { if (-f /var/www/html/maintenance.html) { return 503; } proxy_pass... }
Thanks in advance.
rewrite
statement withtry_files $uri /maintenance.html;
try_files $uri /maintenance.html =404;
(the final =404 is not reached, but allows the /maintenance.html term to be processed within the current location). Also, change the error_page statement toerror_page 503 = @maintenance;
which allows the response code to be changed from 503 to 200.