I have used Caddy to serve live websites but I have never personally tried installing to push localhost server applications like a couple Wordpress local test sites.
I am using Virtual Box on a windows machine. I have a singular VM running Ubuntu 18.04 LTS and have created several LXD 3.0 containers, each with the purpose of hosting a single WordPress site. The config looks like this:
HOST MACHINE – Ubuntu 18.04
[container01] —> WordPress site 1
[container02] —> WordPress site 2
[container03] —> WordPress site 3
Each container is composed of a simple stack to push WordPress:
Ubuntu 18.04 Server
PHP/7
MySQL
Caddy
My question is: How do I enable Caddy features on a local server environment? Is there a way I can turn off automatic certificate grabbing/renewal?
I know how to mark up the caddy.file for live production (insert live domain & valid email). Is there a way I can insert a single container IP address? or simply input ‘localhost’ ?
www.example.com { <-- (do I put 'localhost' here?)
tls admin@example.com <-- (can I try 'tls off')
root /var/www/wordpress
gzip
minify
header / {
Cache-Control "max-age=86400"
Strict-Transport-Security "max-age=31536000;"
X-XSS-Protection "1; mode=block"
X-Content-Type-Options "nosniff"
X-Frame-Options "DENY"
}
header /wp-admin {
Cache-Control no-cache
}
fastcgi / /run/php/php7.0-fpm.sock php
rewrite {
if {path} not_match ^\/wp-admin
to {path} {path}/ /index.php?_url={uri}
}
You can absolutely do any of those things. Just note that Automatic HTTPS sets your ports automatically and without it, the site will be served on port 2015 by default without certificate management. You can then specify the port manually if you want.
My favourite solution is to instead prepend the site label with the HTTP scheme, which keeps the port (implied to be 80) and disables HTTPS features while remaining obvious and readable in the Caddyfile.
The first one would work, although http://localhost and tls off are technically redundant; both serve to disable Automatic HTTPS.
The second one could be tricky… It only responds to requests for localhost, which makes it awkward to get if you’re not making the request for the same machine. For example, with the Caddyfile:
localhost:8080 {
status 200 /
}
I get this result:
❯ curl 127.0.0.1:8080
404 Site 127.0.0.1:8080 is not served on this interface
In that regard, I’d recommend using a more generic catchall, like http:// or :8080 on its own, which will respond to all requests regardless of hostname.