【发布时间】:2020-06-27 22:28:58
【问题描述】:
我在这里阅读此页面https://help.sorryapp.com/en/articles/2783542-install-maintenance-pages-on-nginx 有一个很好的想法,即存在文件意味着 nginx 将路由到维护 html 页面。
但是通过 nginx 文档阅读,似乎位置块中的 if 语句并不理想,而是使用 try 文件。将上面的内容重写为 nginx 想要的方式的正确方法是什么? https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/
我假设是这样的:但是重写呢?
try_files /my/file/path/maint.on
error_page 503 @maintenance_page;
location @maintenance_page {
rewrite ^(.*)$ /maintenance_page.html break;
?
更新 1
这是我当前的配置片段,由于某种原因,即使 maint.on 文件不存在,它也会导致 404。
location / {
if (-f /opt/staytus/staytus/maint.on) {
return 503;
}
port_in_redirect off;
proxy_pass http://example.com:8787/;
}
error_page 503 @Performing-Maintenance;
location @Performing-Maintenance {
rewrite ^(.*)$ Performing-Maintenance.html break;
}
}
对这个问题有什么想法吗?
【问题讨论】: