需求: 国内 ip 访问网站显示正在维护中,非大陆 ip 正常访问。
-
使用 WAF ,直接设置来自 China 的 ip 阻止。 但是他显示的页面是 cloudflare 的禁止访问的页面,不太符合需求。
-
使用 worker ,用以下的代码部署, 来自大陆的 ip 能正常阻止,但是非大陆 ip 会一直重定向:
export default { async fetch(request, env) { let country = request.headers.get('cf-ipcountry') if(country === 'CN') { return new Response('Sorry, this page is not available.', { status: 403 }) } return fetch(request) } } 请教一下大家有什么解决方法没有? (我并不专注于 js 和网络,所以有什么我需要了解的知识,还请不吝指出,我去了解,谢谢)
