【发布时间】:2013-05-17 14:09:34
【问题描述】:
自从IfIsEvil 以来,我一直在尝试使用指令try_files 设置配置,以便维护页面与响应代码503 一起显示,对于任何URI 无一例外,即包括php 页面,如果存在维护文件。
我的配置有两个问题:
- 维护页面不显示 php URI。
- 如果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;
}
}
}
}
我想我的问题也可以这样表述:try_files 可以用作if 控制结构吗?如果不是单独使用,是否可以根据上述目标与其他指令结合使用,不包括if 指令?
编辑:以下是使用if 的解决方案,我目前正在使用它,将其包含在服务器部分中:
error_page 503 @maintenance;
if (-f $document_root/maintenance.html) {
return 503;
}
location @maintenance {
try_files /maintenance.html =404;
}
【问题讨论】:
标签: nginx