Welcome! Log In Create A New Profile

Advanced

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

Posted by seron 
try_files instead of if to return 503 and maintenance file if that file exists
May 29, 2013 05:26AM
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
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 108
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready