簡體   English   中英

Nginx位置:將某些位置免於維護模式

[英]Nginx locations: Exempt certain location from maintenance mode

我有一個在nginx上運行的Symfony 3.4應用程序,並且在nginx中以以下方式實現了維護模式:

 location / {
            # try to serve file directly, fallback to app.php
            try_files $uri /app.php$is_args$args;

 }

 location ~ ^/(app)\.php(/|$) {

            if (-f "/var/www/mysite.com/web/maintenance.html") {
                   return 503;
            }
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT $realpath_root;
 }

error_page 503 @maintenance;

location @maintenance {
           rewrite ^(.*)$ /maintenance.html break;
}

我想從維護模式中排除某個位置,以便該位置繼續由Symfony應用程序提供服務。 因此,對mysite.com/still/available/route請求不會重定向到維護頁面。

那怎么辦?

我找到了答案,實際上,這很明顯。 只需要將“ if”放到根目錄塊(/)中,然后添加另一條位置塊,其路徑在維護模式下應保持可訪問性。 當然,在那兒絕對不能出現if子句:

location / {
            # try to serve file directly, fallback to app.php
            if (-f "/var/www/mysite.com/web/maintenance.html") {
                   return 503;
            }
            try_files $uri /app.php$is_args$args;

 }

location /still/available/route {

            try_files $uri /app.php$is_args$args;

 }

location ~ ^/(app)\.php(/|$) {


            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT $realpath_root;
 }

error_page 503 @maintenance;

location @maintenance {
           rewrite ^(.*)$ /maintenance.html break;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM