Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

try_files instead of if to return 503 and maintenance file if that file exists

$
0
0
Can try_files be used instead of the if directive to unconditionally return 503 response code and maintenance.html if that file exists? It should also do that for any request to php files.

Currently I'm using the following which does what I want:

error_page 503 @maintenance;

if (-f $document_root/maintenance.html) {
return 503;
}

location @maintenance {
try_files /maintenance.html =404;
}

but since IfIsEvil I would like a try_files only solution.

Here's how far I've got with try_files only:

http {
include mime.types;
default_type application/octet-stream;

index index.php index.html index.htm;

server {
listen 80;
server_name rpi;
root /www;

location / {
try_files /maintenance.html $uri $uri/ /index.php?$args;

# pass the PHP scripts to FastCGI server
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
}
}

There are at least two problems with it:

1) The maintenance page does not display for php URIs.
2) The response code 503 is not returned if the maintenance.html file exists.

What is needed for it to work as the configuration using if above?

I also posted this on stackoverflow but had no answers there. http://stackoverflow.com/questions/16693209/nginx-return-response-code-if-a-file-exists-by-using-try-files-only

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>