By Jagadish R
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!
Accepted Answer
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, the caddy
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:
sudo chown -R caddy:caddy /home/username/blog
sudo chmod -R 755 /home/username/blog
sudo systemctl reload caddy
If you prefer not changing permissions in your home folder, you could then change the user as which the cady
service runs as:
sudo nano /lib/systemd/system/caddy.service
User=username
Group=username
sudo systemctl daemon-reload
sudo systemctl restart caddy
In most cases, sticking to /var/www
is usually best.
Let me know if this helps!
- Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.