#5870·photoprism

Server: Support Let's Encrypt AutoTLS via TLS-ALPN-01

Author: lastzeroCreated Sep 29, 2026Updated Sep 29, 2026
Labelsplease-testsecuritysetupconfig

As an administrator running PhotoPrism directly on a server with a public domain name, I want it to obtain and renew a Let's Encrypt certificate by itself, so that I can serve it over HTTPS without setting up a reverse proxy.

PhotoPrism can request a certificate from Let's Encrypt on its own. The related option was hidden so far because this mode was never fully tested. This task makes it ready for testing: the option is shown in the help again, the descriptions of the related options have been reviewed, and the server obtains certificates with the tls-alpn-01 challenge on its regular port. A reverse proxy such as Traefik, Caddy, or nginx remains the recommended setup for most installations.

Once the changes are available in the preview images, they will be tested end to end. If issues remain, the option may be hidden again until they are resolved.

How It Works

Automatic HTTPS is enabled when all of the following apply:

  • PHOTOPRISM_SITE_URL starts with https:// and contains a public domain name, e.g. https://photos.example.com/ (not an IP address, localhost, or a special-use name such as .local, .test, or .internal)
  • PHOTOPRISM_TLS_EMAIL is set to the email address for the Let's Encrypt account
  • PHOTOPRISM_DISABLE_TLS is not true, and PhotoPrism does not listen on a Unix domain socket

PhotoPrism then serves HTTPS on its regular port, PHOTOPRISM_HTTP_PORT (2342 by default), and completes the Let's Encrypt challenge on that same port:

  • No additional port needs to be exposed, but Let's Encrypt always connects to port 443 of the domain. Map port 443 to PhotoPrism's port (e.g. "443:2342" instead of "2342:2342" in compose.yaml), forward port 443 to it on your router, or set PHOTOPRISM_HTTP_PORT to 443.
  • Port 80 is not used. A plain http:// request to PhotoPrism's port gets 400 Bad Request.
  • A certificate is only requested for the domain in the site URL.
  • The certificate is requested with the first HTTPS request after startup, so that request may take a few seconds. It is renewed automatically before it expires.
  • Certificates and the account key are stored in storage/config/certificates, which must be writable and should be on persistent storage.
  • PHOTOPRISM_TLS_CERT and PHOTOPRISM_TLS_KEY are ignored while automatic HTTPS is enabled.
  • If the port is already in use, PhotoPrism logs the error and stops.

Config Options

Environment Variable CLI Flag Description
PHOTOPRISM_SITE_URL --site-url public URL of the site, must start with https:// and contain the domain name
PHOTOPRISM_TLS_EMAIL --tls-email email address to obtain an HTTPS certificate for the site domain from Let's Encrypt, which must reach the Web server on port 443
PHOTOPRISM_HTTP_PORT --http-port port PhotoPrism listens on (2342 by default)
PHOTOPRISM_DISABLE_TLS --disable-tls disables HTTPS/TLS even if the site URL starts with https:// and a certificate or TLS email is configured

In Plus, Pro, and Portal, the Strict-Transport-Security header is also sent in this mode and can be adjusted with the existing options: PHOTOPRISM_STS_SECONDS (max-age, 1 year by default), PHOTOPRISM_STS_SUBDOMAINS, PHOTOPRISM_STS_PRELOAD, and PHOTOPRISM_DISABLE_STS. Browsers remember this header, so a site that sent it should keep serving HTTPS for that time.

Docker Compose Example

yaml
services:
  photoprism:
    image: photoprism/photoprism:preview
    ports:
      - "443:2342" # Let's Encrypt connects to port 443 of the domain
    environment:
      PHOTOPRISM_SITE_URL: "https://photos.example.com/"
      PHOTOPRISM_TLS_EMAIL: "[email protected]"
      PHOTOPRISM_DISABLE_TLS: "false"
      # ... your other settings
    volumes:
      - "./storage:/photoprism/storage" # certificates are stored in storage/config/certificates
      - "./originals:/photoprism/originals"

Command-Line Example

bash
# Allow the binary to bind port 443 without running as root:
sudo setcap cap_net_bind_service=+ep ./photoprism

./photoprism --site-url https://photos.example.com/ --tls-email [email protected] --http-port 443 start

Testing

  1. Point the DNS records of the domain to the server. If the domain has an AAAA record, port 443 must also be reachable over IPv6, since Let's Encrypt may connect over either.
  2. Make sure port 443 of the domain reaches PhotoPrism's port and is not used by another service or proxy.
  3. Start PhotoPrism with the settings above. The log should show server: starting in auto tls mode and server: listening on ....
  4. Open https://photos.example.com/ in a browser. The first request may take a few seconds while the certificate is issued. Check that the browser shows a valid certificate issued by Let's Encrypt.
  5. Restart PhotoPrism and check that the stored certificate is reused: the site should load right away, and storage/config/certificates should contain a file named after the domain.
  6. In Plus, Pro, or Portal, check that responses include a Strict-Transport-Security header that matches the configured options.
  7. Report the result here, including the edition, the version, how port 443 reaches PhotoPrism (port mapping, router, host network, TLS passthrough), and any log lines containing auto tls, acme/autocert, or TLS handshake error. Please remove client IP addresses and Let's Encrypt account or order URLs from log lines before posting them.

Notes for testers:

  • In Plus, Pro, and Portal, set PHOTOPRISM_STS_SECONDS=300 (or PHOTOPRISM_DISABLE_STS=true) while testing, and remove it once the setup works. Browsers remember the Strict-Transport-Security header for that time, one year by default, and refuse plain HTTP for the domain until it expires.
  • Let's Encrypt limits failed validations and duplicate certificates per domain. Fix a failed setup before retrying repeatedly, and keep storage/config/certificates between tests.
  • If a certificate cannot be obtained, PhotoPrism logs a warning in the system log (docker compose logs), at most once per minute. Other TLS handshake errors are only logged with PHOTOPRISM_LOG_LEVEL=debug.
  • A reverse proxy in front of PhotoPrism cannot terminate TLS in this mode. TLS passthrough (e.g. a Traefik TCP router with tls.passthrough=true) should work, but has not been tested yet.

Acceptance Criteria

  • PhotoPrism MUST serve HTTPS on a single listener at PHOTOPRISM_HTTP_HOST:PHOTOPRISM_HTTP_PORT when automatic HTTPS is enabled
  • Certificates MUST be obtained with the tls-alpn-01 challenge on that listener, and only for the domain of the site URL
  • Automatic HTTPS MUST only be enabled for a public domain name, and MUST be disabled by PHOTOPRISM_DISABLE_TLS=true
  • PhotoPrism MUST log the error and stop if the port cannot be bound or a configured certificate cannot be loaded
  • The minimum TLS version MUST remain TLS 1.2, and HTTP/2 MUST remain available
  • PHOTOPRISM_TLS_EMAIL MUST be shown in the help, and the descriptions of the related options MUST mention how they interact with it
  • Plus, Pro, and Portal MUST send the configured Strict-Transport-Security header in this mode, with max-age set by PHOTOPRISM_STS_SECONDS
  • A certificate MUST be issued successfully with the preview images on a server reachable from the Internet
  • The stored certificate MUST be reused after a restart
  • The compose.yaml examples and the documentation SHOULD describe the option once testing is complete
  • Failed certificate requests for the site domain SHOULD be reported in the system log, without flooding it
  • Automatic renewal SHOULD be confirmed on a long-running test instance
  • An optional HTTP listener on port 80 that redirects to HTTPS MAY be added
  • Using the Let's Encrypt staging environment for tests MAY be made configurable