NeD*_*ark 20 maintenance nginx best-practices
我想配置服务器以在它存在时显示维护页面。我试过这个代码并且工作:
location / {
try_files /maintenance.html $uri $uri/ @codeigniter;
}
Run Code Online (Sandbox Code Playgroud)
但我注意到它会带有 200 状态代码,这可能会给搜索引擎造成混乱。我认为最好的做法是返回 503 状态代码。在谷歌上,我找到了几个关于它的相关页面,就像这样。但是,他们使用 if 进行重定向,并且根据 nginx 文档,使用 ifs 是不安全的。
有没有办法不使用if来做到这一点?在这种情况下使用是否安全?
谢谢。
Mik*_*ike 27
这就是我所做的。
if (-f $document_root/maintenance.html) {
return 503;
}
error_page 503 @maintenance;
location @maintenance {
rewrite ^(.*)$ /maintenance.html break;
}
Run Code Online (Sandbox Code Playgroud)
如果文件在那里,它将显示维护页面。删除文件后,您将恢复正常。
小智 5
是的,将 HTTP 503 用于临时非常重要。重定向。我是这样解决的:
server {
listen 80;
server_name joergfelser.at;
root /var/www/joergfelser.at/;
location / {
if (-f $document_root/maintenance.html) {
return 503;
}
... # rest of your config, it's important to have
... # the maintenance case at the very top
}
error_page 503 @maintenance;
location @maintenance {
rewrite ^(.*)$ /maintenance.html break;
}
}
Run Code Online (Sandbox Code Playgroud)
我还写了一篇关于该主题的博客文章:https :
//www.joergfelser.at/redirecting-to-a-custom-nginx-maintenance-page/
快乐维护;)
归档时间: |
|
查看次数: |
27319 次 |
最近记录: |