Help getting simple fileserver without a domain name

1. The problem I’m having:

I am simply trying to start a fileserver for literally ONE file that I can access anywhere.
I have no interest in using a domain name or anything fancy at this stage.

I have a linux (ubuntu) box where I have setup ufw firewall, have allowed ports 80 and 443 for web traffic.

2. Error messages and/or full log output:

I’m not sure at this point, do I need to use https or http , but either way, the site cannot be reached.
Have tried accessing via:
x.x.x.x:80
x.x.x.x
x.x.x.x/test/myfile.txt
x.x.x.x/myfile.txt

3. Caddy version:

2.6.4

d. My complete Caddy config:

:80 {
    root * /home/myname/test
    file_server browse
}

I’m a total noob with web servers, hope this is ok :slight_smile:

Please completely fill out the help topic template, as per the forum rules.

You didn’t share your logs or what you see when making a request with curl -v, so we have no idea what’s not working.

thank you, I am so new to this that some of the suggestions seem irrelevant or I don’t know what to do - the documentation doesn’t give examples of how I’m trying to make it work without a domain :slight_smile:

I have gotten a little further I think by changing to port to 8080, opening that port in my firewall and doing

http://x.x.x.x:8080 {
    root * /home/myname/test
    file_server browse
}

I did run the curl -v http://x.x.x.x:8080/test.m3u as you suggested and got:

Mark bundle as not supporting multiuse
HTTP/1.1 403 Forbidden

Which with some googling, I can’t quite find anything relating to Caddy for this , the file I’m trying to access is ‘.m3u’ file, if that’s relevant :slight_smile:

I have successfully been able to get a response using a simple Caddyfile like

{          
        respond "hello world!"
}                                    

Does it matter i’m using specific folder /home/myname (which I have chowned to caddy) , or must it be something like /var/www ?

thanks

Regardless of the owner, the file must be readable by the user that caddy is running from/as.

You can actually get your config down to this, if you want it accessible from any network interface:

:8080 {
    root * /home/myname/test
    file_server browse
}

Or you can even just use the command line without a config file:

$ caddy file-server --listen :8080 --root /home/myname/test --browse
1 Like

@matt Interesting, well I didn’t try the file-server command line option, thinking it won’t stay running ?
But indeed, that simple line you gave works, the file I’m trying to accessed is served fine, so I do wonder, what in the Caddyfile might be causing the issue.

Thanks!

Yes, you should put your files in /srv or /var/www.

The caddy user won’t have permission to read files in /home because the way Linux permissions work, every directory that is a parent to the target needs to have the executable bit set for the file to be visible to the user trying to access it. The /home directory does not have that bit set, because Linux hides which users exist on the system unless you have permission to see it.

When you run caddy file-server, you’re running Caddy as your own user, instead of the caddy user which is used when you run Caddy as a systemd service. That’s why it worked with that command.

I do recommend running as a service if you need to keep Caddy running long-term.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.