On a recently started droplet running Ubuntu 24.10 I installed Caddy following the standard procedure given in the Caddy docs for Ubuntu. I did not follow the DigitalOcean tutorial for installing Caddy on Ubuntu 22.04.
I have created an user for day-to-day running of the server. I have the Caddyfile
xxxx.com {
encode zstd gzip
root * /home/username/blog
file_server
}
This file is in /etc/caddy
and is owned by root.
When I have debug
at the top of Caddyfile, journalctl
shows that there are permission errors when the root of the static site is accessed.
When I move the static site to /var/www/ and modify the Caddyfile accordingly everything works.
In contrast to the instructions given in the above mentioned tutorial /var/www and all sub directories in it are owned by root (and not caddy) and everything works.
All directories in my static site have a permission of 775 and all files a permission of 664.
Despite going through many tutorials and comments I have no idea why I have the permission errors when the static site is in the user’s home directory.
Any help or pointers would be appreciated. Thanks.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hey Jagadish!
The issue is related to permissions since Caddy runs as the
caddy
user by default. When you try to serve files from your home directory, thecaddy
user doesn’t have access.This is typical for all webservers including Nginx and Apache as well.
The
caddy
user can access/var/www
because it’s set up by default for system services. However, accessing files in/home/username
needs additional permissions as the/home/username
directories are owned by a different user and group.To keep using your home directory, try this:
cady
user:If you prefer not changing permissions in your home folder, you could then change the user as which the
cady
service runs as:In most cases, sticking to
/var/www
is usually best.Let me know if this helps!
- Bobby