nginx 根据时间现在google 抓取网站

大于6点小于 24点时禁止Google 抓取网站内容

location / {
    access_by_lua_block {
        local date = os.date("*t")
        local hour = date.hour

        local ua = ngx.var.http_user_agent
        local is_googlebot = ua and (string.match(ua, "Googlebot") or string.match(ua, "Mediapartners-Google")) ~= nil

        if is_googlebot then
            if hour >= 6 and hour < 24 then
                ngx.status = 403
                ngx.say("Googlebot is only allowed between 00:00 and 06:00.")
                ngx.exit(403)
            end
        end
    }

    # 正常内容
    root /usr/share/nginx/html;
    index index.html;
}

原创文章,作者:admin,如若转载,请注明出处:https://cuue.cn/598.html

(0)
adminadmin
上一篇 2025年8月7日 下午3:17
下一篇 2023年11月18日 下午10:43

相关推荐

发表回复

登录后才能评论
WeChat