Nginx 配置指定时间段不提供服务访问 —— 筑梦之路

需求

部分服务在指定时间段内不允许被访问,用nginx来实现。

配置nginx

# 在需要限制的server里添加如下配置

# 获取本地时间
if ( $time_local ~ "^(\d+)\/(\w+)\/(\d+):(\d+):(\d+):(\d+) \+(\d+)" ) {
  set $hour $4;
}
# 指定时间黑名单,如果为指定时间,返回500
if ( $hour ~ 00|01|05|06|07 ) {
  return 500;
}


# 检查配置

nginx -t

# 重载nginx

nginx -s reload

此处作为记录,仅供参考。

猜你喜欢

转载自blog.csdn.net/qq_34777982/article/details/134439284
今日推荐