相关疑难解决方法(0)

nginx的; 如果文件仅使用try_files存在,则返回响应代码

由于IfIsEvil我一直在尝试使用该指令设置配置,try_files以便维护页面与响应代码503一起显示,对于任何URI都没有例外,即包括php页面,如果存在维护文件.

我的配置有两个问题:

  1. 对于php URI,不显示维护页面.
  2. 如果maintenance.html文件存在,则不返回响应代码503.

我已经看到类似的问题[1],[2]但没有一个try_files只使用(而不是使用if指令)的解决方案,并且如果存在相应的文件,则无条件地为响应代码503的维护页面提供服务.这样的解决方案是否可行?

以下是我目前的非工作conf文件.它不包含503响应代码设置,因为我不明白它应该去哪里,以便它如上所述工作.

worker_processes            1;

error_log                   /var/log/nginx/error.log debug;

events {
    worker_connections      1024;
}

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;
            }
        }
    }
} …
Run Code Online (Sandbox Code Playgroud)

nginx

12
推荐指数
1
解决办法
9795
查看次数

标签 统计

nginx ×1