How to fix Weblate 'Origin checking failed - ... does not match any trusted origins.' on Docker/Traefik

Problem

Whenever a submitting a form on Weblate - in other words, for any POST request such as in the settings - you see the following error message

Keine Berechtigung
CSRF-Verifizierung fehlgeschlagen. Anfrage abgebrochen.
Grund für CSRF-Fehler: Origin checking failed - https://weblate.mydomain.com does not match any trusted origins.

Solution

In my Traefik / docker-compose-based setup (see 10-minute Weblate setup using docker-compose & Traefik for more details), this was easy to fix by appending

WEBLATE_SECURE_PROXY_SSL_HEADER=HTTP_X_FORWARDED_PROTO,https

to the .env file, which is mapped to the environment of the Docker container.

Note that I also have the following set:

WEBLATE_ALLOWED_HOSTS=*
WEBLATE_SITE_DOMAIN=weblate.mydomain.com
#WEBLATE_ENABLE_HTTPS= # DO NOT set this since HTTPS is provided by the reverse proxy

which might be also be required for a working setup.