1. My Caddy version (caddy version
):
v2.0.0-beta.17 h1:x+Ur3uX83j+STerOWsrLDlknXe7z71VnO5xD+H2OwAw=
2. How I run Caddy:
By systemd
a. System environment:
Host on Ubuntu 18.04
LXD Containers on Ubuntu-minimal 18.04
b. Command:
systemd start/reload caddy.service
c. Service/unit/compose file:
[Unit]
Description=Caddy Web Server
Documentation=https://caddyserver.com/docs/
After=network.target
[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --config /etc/caddy/Caddyfile --adapter caddyfile --resume --environ
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile --adapter caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
d. My complete Caddyfile or JSON config:
Frontend container reverse_proxy:
http://domain.com {
reverse_proxy wordpress01:80
log {
output file /var/log/caddy/log_http_domain.com.log
}
}
https://domain.com {
reverse_proxy wordpress01:443
log {
output file /var/log/caddy/log_https_domain.com.log
}
}
On backend container wordpress01 for exemple:
domain.com
root * /var/www/
log {
output file /var/log/caddy/domain.com.log
}
file_server
3. The problem I’m having:
I would like to create a reverse_proxy and backend only with caddy instances.
I had to lxd host, with proxy command to redirect requests from 80 and 443 port to my reverse proxy container, and after, go to container with hostname. On the right backend container, I provide a simple caddyfile for deserve for example, wordpress installation or others applications.
4. Error messages and/or full log output:
At each request
On reverse proxy
tail -f /var/log/caddy/log_https_domain.com.log
2020/03/17 19:13:55.695 ERROR http.log.access.log1 handled request {"request": {"method": "GET", "uri": "/", "proto": "HTTP/2.0", "remote_addr": "127.0.0.1:48270", "host": "domain.com", "headers": {"Dnt": ["1"], "Upgrade-Insecure-Requests": ["1"], "Te": ["trailers"], "User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:73.0) Gecko/20100101 Firefox/73.0"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"], "Accept-Language": ["fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3"], "Accept-Encoding": ["gzip, deflate, br"]}, "tls": {"resumed": true, "version": 772, "ciphersuite": 4865, "proto": "h2", "proto_mutual": true, "server_name": "domain.com"}}, "common_log": "127.0.0.1 - - [17/Mar/2020:19:13:55 +0000] \"GET / HTTP/2.0\" 502 0", "latency": 5.025220824, "size": 0, "status": 502, "resp_headers": {"Server": ["Caddy"]}}
2020/03/17 19:13:56.367 ERROR http.log.access.log1 handled request {"request": {"method": "GET", "uri": "/favicon.ico", "proto": "HTTP/2.0", "remote_addr": "127.0.0.1:48270", "host": "domain.com", "headers": {"User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:73.0) Gecko/20100101 Firefox/73.0"], "Accept": ["image/webp,*/*"], "Accept-Language": ["fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3"], "Accept-Encoding": ["gzip, deflate, br"], "Dnt": ["1"], "Te": ["trailers"]}, "tls": {"resumed": true, "version": 772, "ciphersuite": 4865, "proto": "h2", "proto_mutual": true, "server_name": "domain.com"}}, "common_log": "127.0.0.1 - - [17/Mar/2020:19:13:56 +0000] \"GET /favicon.ico HTTP/2.0\" 502 0", "latency": 0.005896485, "size": 0, "status": 502, "resp_headers": {"Server": ["Caddy"]}}
tail -f /var/log/caddy/log_http_domain.com.log
2020/03/17 19:17:34.185 ERROR http.log.access.log1 handled request {"request": {"method": "GET", "uri": "/", "proto": "HTTP/2.0", "remote_addr": "127.0.0.1:48280", "host": "alainponcel.fr", "headers": {"User-Agent": ["Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:73.0) Gecko/20100101 Firefox/73.0"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"], "Accept-Language": ["fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3"], "Accept-Encoding": ["gzip, deflate, br"], "Dnt": ["1"], "Upgrade-Insecure-Requests": ["1"], "Cache-Control": ["max-age=0"], "Te": ["trailers"]}, "tls": {"resumed": true, "version": 772, "ciphersuite": 4865, "proto": "h2", "proto_mutual": true, "server_name": "alainponcel.fr"}}, "common_log": "127.0.0.1 - - [17/Mar/2020:19:17:34 +0000] \"GET / HTTP/2.0\" 502 0", "latency": 0.004566808, "size": 0, "status": 502, "resp_headers": {"Server": ["Caddy"]}}
On backend:
2020/03/17 19:21:09 http: TLS handshake error from 10.244.32.196:36814: no certificate available for 'wordpress01'
Mar 17 19:28:45 wordpress01 caddy[3025]: 2020/03/17 19:28:45 [INFO][cache:0xc0006388c0] Started certificate maintenance routine
Mar 17 19:28:45 wordpress01 caddy[3025]: 2020/03/17 19:28:45.075 INFO http enabling automatic HTTP->HTTPS redirects {"server_name": "srv0"}
Mar 17 19:28:45 wordpress01 caddy[3025]: 2020/03/17 19:28:45.076 INFO tls cleaned up storage units
Mar 17 19:28:45 wordpress01 caddy[3025]: 2020/03/17 19:28:45.076 INFO http enabling automatic TLS certificate management {"domains": ["domain.com"]}
Mar 17 19:28:45 wordpress01 caddy[3025]: 2020/03/17 19:28:45 [WARNING] Stapling OCSP: no OCSP stapling for [domain.com]: parsing OCSP response: ocsp: error from server: unauthor
ized
Mar 17 19:28:45 wordpress01 caddy[3025]: 2020/03/17 19:28:45.146 INFO autosaved config {"file": "/var/lib/caddy/.config/caddy/autosave.json"}
Mar 17 19:28:45 wordpress01 caddy[3025]: 2020/03/17 19:28:45.146 INFO serving initial configuration
and
root@wordpress01:~# curl -i https://localhost
curl: (35) error:14094438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error
root@wordpress01:~# curl -i http://localhost
HTTP/1.1 308 Permanent Redirect
Connection: close
Location: https://localhost/
Server: Caddy
Date: Tue, 17 Mar 2020 19:26:13 GMT
Content-Length: 0
5. What I already tried:
I tried to create a simple web server instead reverse_proxy on container01 and it’s work. But when I tried to modify to reverse_proxy, it’s not work and try many configurations found on this community, but don’t work. I’m very sorry.
I don’t know if I need to configure something different? Do I need to disable https on reverse proxy, but I don’t how to configure it on caddy file, I see documentation about json configuration.
But what is the best pratice to optimize security? encryption on reverse proxy and encyption too on backend?
I just try to add:
header {
Strict-Transport-Security max-age=31536000; includeSubDomains; preload
Host {http.request.host}
X-Forwarded-Proto {http.request.scheme}
X-Forwarded-For {http.request.remote}
X-Real-IP {http.request.remote}
}
or
header_up X-Forwarded-Proto {scheme}
header_up X-Forwarded-For {remote}
header_up X-Real-IP {remote}
No more working…
Other effort, create an account on this community
6. Links to relevant resources:
https://github.com/caddyserver/caddy/issues/3147
Thanks