问题原文
原帖链接 · Learning · CC BY-SA 4.0
I want Cloudflare WAF to restrict admin section of WordPress site/wp-admin/ and allow access to WP admin section from only two countries India & UAE.
For some reason it block traffic from all countries not only to admin section but also to main website such as www.example.com.
To me below setting should only block admin pages from all countries other than India & UAE and main site should not have any restriction.
Not sure if I am doing anything wrong here as its not working as intended.
Third Image: Fourth Image Fifth image
已采纳解答
原帖链接 · Matteo Manfredi · CC BY-SA 4.0
This is the easy way, supported in all cases. Limit Hostname with equals example.com, URI Path with contains /wp-admin or /wp-admin/ (this is shown in the screenshot below), and Country with is not in { "IN", "AE" }.
If you have access to it (depending on plan type), using a matches regex could make the URI Path filter easier and more focused as it becomes ^/wp-admin, meaning it blocks all those that start with that path.
The full expression, which you can enter when you click "Edit expression" then becomes:
(http.host eq "example.com" and http.request.uri.path contains "/wp-admin/" and not ip.geoip.country in {"IN" "AE"})
The error you are encountering is because you are using OR after the AND group, meaning it's blocking all request to all hostnames and all paths not coming from the UAE or all the requests not coming from India limited to the specific filter you added to the URI in each screenshot.
This you can clearly see in the expression preview below each example.
In your case, if you really wanted to keep the OR in there (isn't required, as shown above, but to show all possible cases), you'd need to filter the URI in each section of Country filtering, before and after the OR.
More info on this can be found in:
- Ruleset Engine · Cloudflare Ruleset Engine docs
- Fields reference · Cloudflare Ruleset Engine docs
- Functions reference · Cloudflare Ruleset Engine docs
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
