1

I'm running a simple nginx server with php-fpm to serve my pages for me.

I've been trying to put it into maintenance mode by redirecting all requests to 503 and then using a custom error page to display the 503.

My problem is, whatever is wrong with my config is causing either nginx to redirect every page including the custom 503 to a built-in default with no information on it, or by changing the config slightly (see below) all my php pages continue to be served. I'm trying to find a way to redirect every request to the maintenance page instead of using nginx's default.

server {
    listen 80 default_server;

    # configuration for SSL and other things not pertaining to the question
    # ...

    root /srv/http;

    index index.php index.html index.htm index.nginx-debian.html;

    error_page 400 /400.php;
    error_page 401 /401.php;
    error_page 403 /403.php;
    error_page 404 /404.php;
    error_page 410 /410.php;
    error_page 500 /500.php;
    error_page 503 /503.php;

    # the method I'm using to enable maintenance involves looking for a file
    # putting this right here causes the entire site to be blocked
    if (-f $document_root/maintenance.on) {
        return 503;
    }

    location / {
        # putting the 503 checker here instead does not stop requests to index.php
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
    }
}

I've tried multiple combinations and it is really doing my head in. What am I doing wrong?

0 Answers0