如果文件存在,configurationnginx来提供503

我想设置nginx返回503如果一个特定的文件存在(可能类似“升级”)。 我试图使用try_files指令,但是当它find/upgrading.html文件时,它会提供它而不是遵循指令。 这是为什么?

 location / { try_files /upgrading.html @keepgoing; } location = /upgrading.html { return 503; } location @keepgoing { #do stuff here to do whatever I would normally do... } 

在我打开debugging的日志中,我看到以下内容:

 3388 2010/07/01 19:44:21 [debug] 76327#0: *8 test location: "/" 3389 2010/07/01 19:44:21 [debug] 76327#0: *8 using configuration "/" 3390 2010/07/01 19:44:21 [debug] 76327#0: *8 http cl:-1 max:52428800 3391 2010/07/01 19:44:21 [debug] 76327#0: *8 generic phase: 2 3392 2010/07/01 19:44:21 [debug] 76327#0: *8 post rewrite phase: 3 3393 2010/07/01 19:44:21 [debug] 76327#0: *8 generic phase: 4 3394 2010/07/01 19:44:21 [debug] 76327#0: *8 generic phase: 5 3395 2010/07/01 19:44:21 [debug] 76327#0: *8 access phase: 6 3396 2010/07/01 19:44:21 [debug] 76327#0: *8 access phase: 7 3397 2010/07/01 19:44:21 [debug] 76327#0: *8 post access phase: 8 3398 2010/07/01 19:44:21 [debug] 76327#0: *8 try files phase: 9 3399 2010/07/01 19:44:21 [debug] 76327#0: *8 try to use file: "/upgrading.html" "/usr/local/nginx/html/upgrading.html" 3400 2010/07/01 19:44:21 [debug] 76327#0: *8 try file uri: "/upgrading.html" 3401 2010/07/01 19:44:21 [debug] 76327#0: *8 content phase: 10 3402 2010/07/01 19:44:21 [debug] 76327#0: *8 content phase: 11 3403 2010/07/01 19:44:21 [debug] 76327#0: *8 content phase: 12 3404 2010/07/01 19:44:21 [debug] 76327#0: *8 http filename: "/usr/local/nginx/html/upgrading.html" 

似乎无法find指令,但它在那里,所以不知道我做错了什么。

另外,更一般地说,这是解决这个问题的可接受的方法吗? 其他方法来做到这一点?

从此页面: https : //calomel.org/nginx.html

 ## System Maintenance (Service Unavailable) if (-f $document_root/system_maintenance.html ) { error_page 503 /system_maintenance.html; return 503; } 

我相信“-f”的重要部分是testing文件是否存在。