Caddy 怎么封禁 ip?

2023-04-03 14:01:30 +08:00
 azev

比较纳闷这个为什么基本 Google 不到什么资料
nginx 的倒是比较成熟 include 一个文件就可以
caddy 我搜到大致是有两个方案?一个是 remote_ip 指令,一个是 ipfilter 这个第三方模块?
但是貌似都不支持外部文件(随时更新封禁列表) 有没有比较熟悉的?

1006 次点击
所在节点    问与答
7 条回复
azev
2023-04-03 14:03:04 +08:00
append:如果有内置解封规则最好
serco
2023-04-03 14:06:09 +08:00
{
# Import the ipfilter module
import ipfilter
}

example.com {
# Block IP addresses from file
@blocked {
ipfilter file /path/to/blocked_ips.txt
}

# Define your routes
route / {
# Use the `handle` directive to apply the middleware
handle @blocked {
respond "Access denied"
}
respond "Hello, World!"
}
}

ChatGPT 给的答案
azev
2023-04-03 14:08:15 +08:00
@serco 多谢 我试试
azev
2023-04-03 14:31:21 +08:00
@serco 看了下 这个 ipfilter 模块看来是只能支持 1.0 版本的 caddy ,不支持 2.0 的
2.0 的有个 caddy-maxmind-geolocation 但貌似不是很灵活 必须使用 geoip 数据库才行
azev
2023-04-03 14:35:07 +08:00
我也问了下 ChatGPT 貌似可以这样
example.com {
@block {
not remote_ip {file /path/to/blocked_ips.txt}
}
respond @block "Access denied" 403
reverse_proxy 127.0.0.1:8080
}
alamak76
2023-04-04 12:57:06 +08:00
你可以用免费工具下载 IP 库。

https://www.ip2location.com/free/visitor-blocker
qgbcs1
298 天前
Error: adapting config using caddyfile: /home/qgb/caddy/Caddyfile:5 - Error during parsing: File to import not found: ipfilter

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/929405

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX