Hi, can I use caddy to serve root directory over http for specific IP? Currently I’m using python -m SimpleHTTPServer under / directory. However it doesn’t limit client access.
You can use Caddy’s proxy
middleware or mount the remote disk as a local one; either one should work. But to use proxy
you’ll have to have a server running on that machine too. To filter by client IP you should use the ipfilter plugin.
Hi @amosbird,
You can definitely achieve functionality similar to Python’s SimpleHTTPServer with Caddy, and you can also have it only serve it for requests to a specific IP. As Matt mentions, if you want to limit it to requests FROM specific IP addresses, ipfilter
is your go-to middleware.
You could do it with a one-liner command - assuming the IP you want to serve content on is 192.168.1.100
and the directory you want to serve is /var/www/public
:
echo -e "http://192.168.1.100\nroot /var/www/public" | caddy -conf stdin
Alternately, you could write a Caddyfile in the directory you want to serve:
http://192.168.1.100
root /var/www/public
Then just run caddy
.
Thanks! However I got 404 while running the one liner. BTW, could you also provide an example of ipfilter? my server is 10.60.1.142 and my dedicated client is 10.61.3.88.
Did you change the /var/www/public
to the folder you actually want to serve files from? There’s no difference between my two above examples (Caddyfile vs. piped config).
The docs for ipfilter
has lots of examples - Matt linked them earlier: https://caddyserver.com/docs/http.ipfilter
I did this echo -e "10.60.1.142\nroot /" | caddy -conf stdin
and get 404.
um, so I just need
ipfilter / {
rule allow
ip 10.61.3.88
}
?
That ipfilter
block looks good!
Can you let me know what happens when you type cat /index.*
?
there isn’t an index.*. I just want to share the file directory…
A 404 error is expected behaviour without an index file. If you want Caddy to display a directory listing, you can use the browse
directive as well.
Great! It works now. Thank you.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.