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
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