Can't get caddy to work with caddyfile-per-vhost

Hi,

First off, I’m completely new to Caddy, but loving the simplicity so far. However, for the love of everything I’ve tried, I can’t get this simple set-up to work what so ever. I hope I’m just doing something silly and that this can be solved easily.

On my VPS, I host my applications (websites) in /var/www/<domain_name>/web.

My previous setup was a simple LAMPP-stack with vhost files for all my domains, pointing to the “web” directory as shown in the path above.

How would you do this with Caddy?

I’m running Caddy 0.9.5. (freshly installed today on Ubuntu 14.04 LTS, everything fully updated)

I’m trying to use import to load a Caddyfile per host, so I’ve tried the following:

# /etc/caddy/Caddyfile
import /var/www/*/Caddyfile
import caddy-php.conf
# /etc/caddy/caddy-php.conf
fastcgi / /var/run/php/php7.1-fpm.sock php
# /var/www/harold.info/Caddyfile
harold.info
root    /var/www/_default
tls     harold@iedema.me
# /var/www/joii.harold.info/Caddyfile
joii.harold.info
root    /var/www/joii.harold.info/web
tls     harold@iedema.me

When running caddy, I’m presented with the following error:

2017/04/07 19:05:47 Caddyfile:2 - Parse error: Wrong argument count or unexpected line ending after 'root'

So I thought, maybe I need to put brackets around the directives in each file? In my head, that totally makes sense…
So, I did this for each Caddyfile in each “project”:

# /var/www/harold.info/Caddyfile
harold.info {
    root    /var/www/_default
    tls     harold@iedema.me
}

However, now I’m getting this error:

Activating privacy features...2017/04/07 19:07:14 [INFO][fastcgi] acme: Obtaining bundled SAN certificate
2017/04/07 19:07:14 [fastcgi] failed to get certificate: acme: Error 400 - urn:acme:error:malformed - Error creating new authz :: DNS name does not have enough labels

I’m guessing the brackets are parsed “as part of the domain name” ?
I could be totally wrong and just doing something silly…

please help :smiley:

Hi Harold, welcome! If you have more than one site per Caddyfile (which you do, since you’re importing them all into the same Caddyfile), you need curly braces around the site definition: The Caddyfile — Caddy Documentation

Hi Matt,

Thanks for the quick reply!

However, I’m already doing exactly what you’re suggesting. Look at the last examples.

Unless I’m completely missing something… :confused:

The fastcgi directive has to be in a site definition too.

1 Like

Aahhh, that works!

So from what I get is that each directive (vhost) must have everything configured by itself. No global configuration.

Now it makes sense why this didn’t work!

Thank you very much! :smiley:

1 Like

Bingo. The new website’s Caddyfile tutorial will mention this specifically so hopefully that’ll clear things up.

1 Like

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