nginxがサイトをメンテナンス状態にすると、メンテナンスファイルがブロックされるか、すべてのファイルが引き続き許可されます。

nginxがサイトをメンテナンス状態にすると、メンテナンスファイルがブロックされるか、すべてのファイルが引き続き許可されます。

私は自分のページを提供するために、php-fpm を備えたシンプルな nginx サーバーを実行しています。

すべてのリクエストを 503 にリダイレクトし、カスタム エラー ページを使用して 503 を表示することで、メンテナンス モードにしようとしています。

私の問題は、私の設定に何らかの問題があるために、nginxがすべてのページをリダイレクトしていることです含むカスタム 503 を、情報のない組み込みのデフォルトに変更するか、構成を少し変更することで (下記参照)、すべての PHP ページが引き続き提供されます。nginx のデフォルトを使用する代わりに、すべてのリクエストをメンテナンス ページにリダイレクトする方法を見つけようとしています。

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

複数の組み合わせを試してみましたが、本当に頭が混乱してしまいます。何が間違っているのでしょうか?

関連情報