Files
wekan/docs/Platforms/Webserver/Local-self-signed-TLS.md
T
Lauri Ojansivu 37d2397603 Caddyfile examples are Caddy 2, and the snap's Caddy proxies to where WeKan listens.
The snap runs Caddy 2, and migrate-caddyfile-v1-to-v2.sh treats a Caddyfile
that `caddy adapt` rejects as Caddy v1: it moves it to Caddyfile.v1.bak-<n>
and, when it cannot convert it, writes the default in its place - on every
start. 19 Caddyfile examples in the docs were Caddy v1 (`proxy / localhost:3001
{ websocket transparent }`, `browse`, `fastcgi`, `tls self_signed`, `ext`,
v1 `log`/`errors`, `root /path`), so a file copied from the snap install page
was renamed each time it was put back. All are now Caddy 2 (reverse_proxy,
file_server browse, php_fastcgi, tls internal, try_files, log output) and pass
`caddy adapt` with Caddy 2.11.7. Also:

- `http://X https://X { tls ... }` became `X {`: Caddy 2 refuses TLS on the
  http address and redirects to https by itself;
- the Windows examples `load` the certs folder - Caddy 2's load takes folders;
- the Docker Meteor3 Caddyfile gave the Let's Encrypt and CloudFlare variants
  of one site the same host, which Caddy 2 refuses as ambiguous; each has its
  own host now;
- Caddy.md's logs example and its systemd unit, installer and setcap are
  Caddy 2 (`caddy run --config`, no getcaddy.com, no -conf/-agree/-email).

The fallback template the migration writes proxied to localhost:3000. With
Caddy enabled the snap runs WeKan on caddy-bind-port (default 3001), so a
migrated site pointed at nothing. Both templates now read the snap settings
from caddy-control's environment - `:{$CADDY_PORT:8080}` and `reverse_proxy
localhost:{$CADDY_BIND_PORT:3001}` - so `snap set wekan port=...` reaches
Caddy on the restart the configure hook already does; that hook's sed lines
only ever matched Caddy v1 lines. The commented TLS example in the template
had `protocols h1` inside a site and a stray `}`, so uncommenting it failed;
it uses `alpn http/1.1` now.

tests/caddyfileExamplesV2.test.cjs finds every Caddyfile in the docs and the
snap, fails on Caddy v1 syntax and on a Caddy 1 command line, checks the
templates' ports, and with a Caddy 2 binary runs `caddy adapt` on all 30.
snapStagePackages.test.cjs pinned the wrong port 3000 and now pins 3001.

Thanks to Group-Deed and xet7 !
2026-10-15 22:05:49 +03:00

4.8 KiB

From ksaadDE at https://github.com/wekan/wekan-snap/issues/167

Hi,

I've read that in e.g. https://github.com/wekan/wekan-snap/issues/118 there is assumed that local https wouldn't work (even not for ips). I provide a small guide to fix this.

Despite the fact that you should never use self-signed certs in production. You mess up your TLS Certificate Verification/Validation and therefore exposing yourself to various risks in cyberspace. For limited local uses it can be valid!

General Config

In both cases your /etc/hosts should have a entry that routes your "domain" wekan.local to 127.0.0.1 (=localhost) like this:

127.0.0.1 wekan.local

You need to enable caddy sudo snap set wekan caddy-enabled='true' and set the root-url to https://wekan.local. Keep in mind that 3001 is the wekan webapp port, not the caddy port(!). Caddy will use 80 and 443.

Option 1: tls internal, Caddy's own local certificate authority

Your /var/snap/wekan/common/Caddyfile should look like this:

https://wekan.local {
        tls internal
        reverse_proxy localhost:3001
}

Restart your Wekan snap service: sudo snap restart wekan && sudo snap restart wekan.caddy voila!

Drawback: Caddy 2 signs the certificate with its own local certificate authority and renews it by itself, but browsers trust it only on a computer where that authority's root certificate is installed (caddy trust, or import it by hand). Meant for testing, not for production. (Caddy 1's tls self_signed, which this replaces, made a certificate that lasted only seven days.)

Option 2: Custom, long-living, self-signed TLS Cert

Your /var/snap/wekan/common/Caddyfile should look like this:

https://wekan.local {
        tls /var/snap/wekan/common/certs/certificate.pem /var/snap/wekan/common/certs/key.pem
        reverse_proxy localhost:3001
}

Create a bash script using sudo nano /var/snap/wekan/common/certs/certgen.sh :

#!/bin/bash
# this script checks existence of CERTFILE and KEYFILE in current directory and moves existing files to FILE.old then generating new TLS certs (self-signed) with a CN of $SERVERNAME,  finally it restarts the snap wekan service + caddy

ROOTPATH="/var/snap/wekan/common/certs"

SERVERNAME="wekan.local"

CERTFILE="$ROOTPATH/certificate.pem"
KEYFILE="$ROOTPATH/key.pem"


if [ -f "$CERTFILE" ]; then
        echo "[+] backing up '$CERTNAME'";
        sudo mv "$CERTFILE" "$CERTNAME.old";
fi

if [ -f "$KEYFILE" ]; then
        echo "[+] backing up '$KEYFILE'";
        sudo mv "$KEYFILE" "$KEYFILE.old";
fi

echo "[+] Trying to generate certs";

sudo openssl req -newkey rsa:4096 \
            -x509 \
            -sha256 \
            -days 3650 \
            -nodes \
            -out "$CERTFILE" \
            -keyout "$KEYFILE" \
            -subj "/C=SI/ST=Ljubljana/L=Ljubljana/O=Security/OU=IT Department/CN=$SERVERNAME" &>/dev/null

if [ ! -f "$CERTFILE" ]; then
        echo "[-] can't fiund '$CERTFILE' seemingly the generation failed";
        exit
fi

if [ ! -f "$KEYFILE" ]; then
        echo "[-] can't find '$KEYFILE' seemingly the generation failed";
        exit
fi

echo "[+] completed TLS-Cert generation";

# restart snap wekan && wekan.caddy
echo "[+] restarting snap wekan service";
sudo snap restart wekan &>/dev/null
sudo snap restart wekan.caddy &>/dev/null
echo "[+] completed restart snap wekan service";
echo " ";
echo "[i] please check https://$SERVERNAME/"

This file generates two files certificate.pem and key.pem, then checks their existence in /var/snap/wekan/common/certs/ (same dir). If the CERTFILE or KEYFILE already existing, it will move the existing files to .old. Then it restarts the wekan services wekan and caddy. Afterwards it shows you the address to visit.

Make the sh file executable sudo chmod u+x ./runfiles.sh

Finally, run sudo ./runfiles.sh and it should work at the address being recommended to visit.

Things to keep note of

  • Don't try to use load it won't work!
  • Don't mess around without a SERVERNAME... it won't work
  • Don't use the default caddy file with this tls subdirectives. It won't work and break into No Connection or PR_END_OF_FILE_ERROR (firefox)
  • Caddy 1 had bugs with self_signed certificates; the snap's Caddy 2 uses tls internal instead
  • FIREWALL CONFIG: Don't forget to block in and out 3001 for outside connections (e.g. using ufw or nfttables / iptables)

Sources:

Greetings from Germany <3