I am trying to implement IP whitelist on my Caddy v2 configuration. Something equivalent to NGINX configuration like:
allow 1.1.1.1;
allow 8.8.8.8;
deny all;
My current Caddy configuration pretty straight forward:
my.website.com {
reverse_proxy http://127.0.0.1:3000 {
}
}
Thanks
3
Answers
I am not sure it is possible directly in Caddy, but you can add a middleware/plugin to do this.
Here is the link you can get it : https://github.com/pyed/ipfilter
According to the doc of this middleware, to you want to allow only the 2 IPs you wrote, you should probably do something like this :
I also think if want to block every requests, not just the
/
, you have to writeipfilter /*
instead ofipfilter /
.You can try something like this in caddy v2:
I’m not saying qed’s answer is wrong, however I couldn’t get it to work in my case (possibly due to using import templates inside a handle?)…
My solution was… Old config:
This changed to:
Simply adding those two lines allows my site to be accessed on that IP. A test curl from a different IP returned the 403 error.
This is done on Caddy 2.4.6