你们是不是会遇到这样的需求,某个新版本上线时,需要停机(这里不考虑灰度发布),如果不设置维护页面,用户访问时就会很不友好,显示404或者显示503;我们就希望在维护的时间段内,用户访问域名时显示系统正在维护中,你们都是怎么实现的呢?
这里我分享下在nginx如何配置实现:
1、首页新增一个conf文件,放在某个路径下,如:/etc/tmp/page.conf
2、要维护的域名下 include 该配置文件
3、对应满足条件的请求用户,rewrite到指定页面
具体配置如下:
1)、
location / {
#这里你要做的条件判断,放在配置文件里,需要时去掉注释#
# include /etc/tmp/page.conf;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header remote-port $remote_port;
proxy_pass http://gateway_servers/;
}
2.1)、这个写在/etc/tmp/page.conf里
location / {
root /data/page/; #你要展示的页面放在这个路径下
index index.html;
}
2.2)、
if ( $update_flag != 1 ) # 这里具体可以参考上一篇文章
{
return 302 https://xxx.xxx.com/page/index.html;
}
4)、index.thml
自己写个简单页面,注明维护时间
这个方法在配置上稍等有点复杂,但还是很实用的,你们一般是怎么做的呢?