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

我嘗試了多種組合,這真的讓我很頭痛。

相關內容