我有一个PHP的Web应用程序的nginxconfiguration,我想使它有一个额外的目的,我似乎无法find一个办法来实现它。 我目前的nginxconfiguration如下:
/
/intro/*
重写为非PHPdynamic“市场营销”网站的静态HTML页面 /maintenance.html
如果存在于磁盘上,只在部署期间存在) /maintenance.html
不存在,请通过FastCGI向PHP发送请求 最终结果是在部署过程中静态页面保持可用,后端PHP应用程序可以在部署发生时进行维护。 server
configuration块的重要部分如下所示:
rewrite ^/$ /marketing/index.html last; rewrite ^/intro/(.*)$ /marketing/$1.html last; try_files $uri /maintenance.html @webapp; location @webapp { rewrite ^(.*)$ /index.php?url=$1 last; } include php.conf;
( php.conf
configuration处理location ~ \.php$
位置,并执行所有通常的fastcgi_param
设置。没有任何项目特定的,所以我没有发布该块。)
除了上述之外,我希望能够做的是当“维护模式”打开时,为标准HTTP请求提供/maintenance.html
,但在处理AJAX请求时响应一些JSON。 我发现我可以安全地返回基本内容:
if ($http_x_requested_with = XMLHttpRequest) { return 503 '{"maintenance":true}'; }
但是,这显然发生在所有请求上,而不仅仅是/maintenance.html
被提供的那些请求。 看来我需要一些标志,因为try_files
不允许你做额外的事情取决于它select的文件或位置。
有什么办法可以将nginxconfiguration为返回HTML和JSON维护模式的详细信息?
编辑:更多的思考,也许将maintenance.html
完全移出try_files
将是很好的,所以它可以用503状态而不是200来提供。