serksimper
5/11/2020 - 1:27 PM

Set up Caddy Webserver Permissions/Folders on Linux

https://dev.to/legobox/another-kickass-server-called-caddy-4o1f

First, put the caddy binary in the system wide binary directory and give it appropriate ownership and permissions:
    sudo cp /path/to/caddy /usr/local/bin
    sudo chown root:root /usr/local/bin/caddy
    sudo chmod 755 /usr/local/bin/caddy

Give the caddy binary the ability to bind to privileged ports (e.g. 80, 443) as a non-root user:

    sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/caddy

Set up the user, group, and directories that will be needed:

    sudo groupadd -g 33 www-data
    sudo useradd \
      -g www-data --no-user-group \
      --home-dir /var/www --no-create-home \
      --shell /usr/sbin/nologin \
      --system --uid 33 www-data

    sudo mkdir /etc/caddy
    sudo chown -R root:www-data /etc/caddy
    sudo mkdir /etc/ssl/caddy
    sudo chown -R root:www-data /etc/ssl/caddy
    sudo chmod 0770 /etc/ssl/caddy
    
Place your caddy configuration in the appropriate directory and give it appropriate ownership and permissions:


    sudo cp /path/to/Caddyfile /etc/caddy/
    sudo chown www-data:www-data /etc/caddy/Caddyfile
    sudo chmod 444 /etc/caddy/Caddyfile
    
Create the home directory for the server and give it appropriate ownership
and permissions:


    sudo mkdir /var/www
    sudo chown www-data:www-data /var/www
    sudo chmod 555 /var/www
    
 Put your website into place for it to be served by caddy:
 
    sudo cp -R example.com /var/www/
    sudo chown -R www-data:www-data /var/www/example.com
    sudo chmod -R 555 /var/www/example.com
    
Start building Caddyfile

    example.com {
        root /var/www/example.com
        ...
    }