Is there a tutorial how to use caddy with domains in digitalocean?

Hi guys,

sorry for making a topic which it’s uncomfortable for anyone would help me.

I have never understood how caddy works since I have experience with Apache 2 and I’m thinking to replace HTTP service with Caddy.

It only worked that I typed “Caddy” with config files and it returned 404 not found

The biggest issue I was unable to do sudo
"setcap cap_net_bind_service=+ep ./caddy"

Failed to set capabilities on file `./caddy’ (Invalid argument)
The value of the capability argument is not permitted for a file. Or the file is not a regular (non-symlink) file

Anyway, is there a guide how to get started with Caddy and DigitalOcean with hosted domain?

First you’ll want to be root. In your terminal type: sudo su now the prompt will show root@.

Type caddy -version and see if it can find and show you the version you run. If it shows the version you can skip the installation step.

If its not installed download caddy and move it to a nice location like this.
curl --silent --show-error --fail --location --header “Accept: application/tar+gzip, application/x-gzip, application/octet-stream” -o - “https://caddyserver.com/download/build?os=linux&arch=amd64” | tar --no-same-owner -C /usr/local/bin/ -xz caddy && chmod 0755 /usr/local/bin/caddy

curl https://getcaddy.com | bash

Next type whereis caddy. This will tell you the installed location of caddy. If you installed as above then it will show: caddy: /usr/local/bin/caddy

Now you can type: setcap cap_net_bind_service=+ep /usr/local/bin/caddy. Notice the last part is the place where caddy is located on your system. In the documentation example that is ./caddy (in the current directory).

Now if your system is Ubuntu 16.04 or one of the other Linux distributions that support SystemD then you can follow these instructions to install caddy as a system service. https://github.com/mholt/caddy/tree/master/dist/init/linux-systemd

Hopefully that helps.

4 Likes

^ That’s pretty good (thanks @slightfoot!), although I’d recommend curl https://getcaddy.com | bash to install Caddy instead of that much longer chain of commands; this one command will put Caddy into /usr/local/bin for you.

1 Like

@matt Good point, I forgot about that. I was using some commands from my Dockerfile/s. I’ll update the post.

1 Like

@slightfoot Thanks! Im going to try your idea.

Anyway, would you mind to tell me how to add multiple domains? In that case I have 2 domains as 2 folders in /var/www

site1.com
site2.com

Then I make caddyfile.conf inside of www folder… I wonder if I write like that

Caddyfile.conf

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

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

Im really curious how to activate domain with caddy like apache 2, I added IP hostname to domains in digitalocean. I will let you know what are errors.

It looks like it’s working…

http://138.68.18.179:2015/

Now, I need to understand how to point with domains

EDIT: http://www.powerupware.com:2015/

It’s supposed to display “HELLO WORLD” and remove port 2015

Isn’t index.html as default with caddy?

Can you help me for my progress?

Your configuration example is just fine to work with the default launch port of 2015.

powerupware.com:80, www.powerupware.com:80, powerupware.com:443, www.powerupware.com:443 {
    root /var/www/powerupware.com
}

site2.com:80, www.site2.com:80, site2.com:443, www.site2.com:443 {
    root /var/www/site2.com
}

The default port when you launch caddy is 2015. Instead you can specify port :80 HTTP in your configurations and :443 for HTTPS. I specify the port numbers because I’m old like that but these formats also work.

powerupware.com:http, www.powerupware.com:http, powerupware.com:https, www.powerupware.com:https {
    root /var/www/powerupware.com
}
http://powerupware.com, http://www.powerupware.com, https://powerupware.com, https://www.powerupware.com {
    root /var/www/powerupware.com
}

You can find more information about all that here: The Caddyfile — Caddy Documentation

index.html should load by default. But it looks like you don’t have one in the root that you specified http://138.68.18.179:2015/index.html Perhaps you should check the permissions/ownership on the files. You can run cd /var/www/powerupware.com && ls -l and put the results in your next post if you want more help with that.

Non-localhost sites are served over 80 and 443 by default, with HTTP redirecting to HTTPS.

So this config:

powerupware.com:80, www.powerupware.com:80, powerupware.com:443, www.powerupware.com:443 {
    root /var/www/powerupware.com
}

site2.com:80, www.site2.com:80, site2.com:443, www.site2.com:443 {
    root /var/www/site2.com
}

should probably become, simply:

powerupware.com, www.powerupware.com {
    root /var/www/powerupware.com
}

site2.com, www.site2.com, site2.com, www.site2.com {
    root /var/www/site2.com
}

Sorry for late reply. I was busy at work, I hope you don’t mind.

I’ve followed your guide… I’m not sure these results aren’t working-

I’ve changed config in caddy file as:

powerupware.com:80, www.powerupware.com:80, powerupware.com:443, www.powerupware.com:443 {
    root /var/www/powerupware.com
}

and I entered www.powerupware.com and it’s not working, anyone can correct this mistake?

Also here is permission in this directory

-rw-r–r-- 1 root root 12 Aug 1 00:01 index.html

Looks like it is was serving still on port 2015 did you forget service caddy restart?

Ah, I didn’t know this command exist, so it worked, thanks!

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