Skip to content

Commit e67a28f

Browse files
thePanzmaxhelias
authored andcommitted
feat: Allow local certificates to be used by Caddy
1 parent a36ce26 commit e67a28f

File tree

4 files changed

+47
-13
lines changed

4 files changed

+47
-13
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ A [Docker](https://www.docker.com/)-based installer and runtime for the [Symfony
3333
3. [Support for extra services](docs/extra-services.md)
3434
4. [Deploying in production](docs/production.md)
3535
5. [Debugging with Xdebug](docs/xdebug.md)
36-
6. [Using a Makefile](docs/makefile.md)
37-
7. [Troubleshooting](docs/troubleshooting.md)
36+
6. [TLS Certificates](docs/tls.md)
37+
7. [Using a Makefile](docs/makefile.md)
38+
8. [Troubleshooting](docs/troubleshooting.md)
3839

3940
## License
4041

docker/caddy/Caddyfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
{$SERVER_NAME}
77

8+
{$CADDY_EXTRA_CONFIG}
9+
810
log
911

1012
route {

docs/tls.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# TLS Certificates
2+
3+
## Trusting the Authority
4+
5+
With a standard installation, the authority used to sign certificates generated in the Caddy container is not trusted by your local machine.
6+
You must add the authority to the trust store of the host :
7+
8+
```
9+
# Mac
10+
$ docker cp $(docker compose ps -q caddy):/data/caddy/pki/authorities/local/root.crt /tmp/root.crt && sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain /tmp/root.crt
11+
# Linux
12+
$ docker cp $(docker compose ps -q caddy):/data/caddy/pki/authorities/local/root.crt /usr/local/share/ca-certificates/root.crt && sudo update-ca-certificates
13+
# Windows
14+
$ docker compose cp caddy:/data/caddy/pki/authorities/local/root.crt %TEMP%/root.crt && certutil -addstore -f "ROOT" %TEMP%/root.crt
15+
```
16+
17+
## Using Custom TLS Certificates
18+
19+
By default, Caddy will automatically generate TLS certificates using Let's Encrypt or ZeroSSL.
20+
But sometimes you may prefer using custom certificates.
21+
22+
For instance, to use self-signed certificates created with [mkcert](https://github.com/FiloSottile/mkcert) do as follows:
23+
24+
1. Locally install `mkcert`
25+
2. Create the folder storing the certs:
26+
`mkdir docker/caddy/certs -p`
27+
3. Generate the certificates for your local host (example: "server-name.localhost"):
28+
`mkcert -cert-file docker/caddy/certs/tls.pem -key-file docker/caddy/certs/tls.key "server-name.localhost"`
29+
4. Add these lines to the `./docker-compose.override.yml` file about `CADDY_EXTRA_CONFIG` environment and volume for the `caddy` service :
30+
```diff
31+
caddy:
32+
+ environment:
33+
+ CADDY_EXTRA_CONFIG: "tls /etc/caddy/certs/tls.pem /etc/caddy/certs/tls.key"
34+
volumes:
35+
+ - ./docker/caddy/certs:/etc/caddy/certs:ro
36+
- ./public:/srv/app/public:ro
37+
```
38+
5. Restart your `caddy` container

docs/troubleshooting.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@
44

55
If you work on linux and cannot edit some of the project files right after the first installation, you can run `docker compose run --rm php chown -R $(id -u):$(id -g) .` to set yourself as owner of the project files that were created by the docker container.
66

7-
## Fix Chrome/Brave SSL
8-
9-
If you have a TLS trust issues, you can copy the self-signed certificate from Caddy and add it to the trusted certificates :
10-
11-
# Mac
12-
$ docker cp $(docker compose ps -q caddy):/data/caddy/pki/authorities/local/root.crt /tmp/root.crt && sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain /tmp/root.crt
13-
# Linux
14-
$ docker cp $(docker compose ps -q caddy):/data/caddy/pki/authorities/local/root.crt /usr/local/share/ca-certificates/root.crt && sudo update-ca-certificates
15-
# Windows
16-
$ docker compose cp caddy:/data/caddy/pki/authorities/local/root.crt %TEMP%/root.crt && certutil -addstore -f "ROOT" %TEMP%/root.crt
17-
187
## HTTPs and Redirects
198

209
If Symfony is generating an internal redirect for an `https://` url, but the resulting url is `http://`, you have to uncomment the `TRUSTED_PROXIES` setting in your `.env` file.
2110
For more details see the [Symfony internal redirect documentation](https://symfony.com/doc/current/routing.html#redirecting-to-urls-and-routes-directly-from-a-route).
11+
12+
## TLS/HTTPS Issues
13+
14+
See more in the [TLS section](tls.md)

0 commit comments

Comments
 (0)