Serve root filesystem to specific IP

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 and the directory you want to serve is /var/www/public:

echo -e "\nroot /var/www/public" | caddy -conf stdin

Alternately, you could write a Caddyfile in the directory you want to serve:
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 and my dedicated client is

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:

I did this echo -e "\nroot /" | caddy -conf stdin and get 404.

um, so I just need
ipfilter / {
rule allow

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.