Setting up HTTPS for self-hosted Sentry
Sentry, a very powerful error-tracking tool, can easily be self-hosted. Their self-hosted Github repo and documentation explain this very well.
To add HTTPS support to the instance isn’t explained in detail though. In this post I give a brief description of how HTTPS using Traefik and Let’s Encrypt can be added quite easily.
Traefik
Traefik is a reverse-proxy, meaning it is the door to your application, Sentry in our case. Traefik routes incoming requests to specific applications based on routing rules. As Sentry comes with Nginx, and Nginx is also a reverse-proxy, we are going to disable Nginx.
Enabling HTTPS
Follow these steps to enable HTTPS for your self-hosted Sentry:
-
Install self-hosted Sentry according to instructions
-
Create a new folder called
traefikin your home directory -
Add a
docker-compose.ymlwith the following content
version: "3.3"
services:
traefik:
image: "traefik:v2.9"
container_name: "traefik"
network_mode: "host"
restart: "unless-stopped"
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.websecure.address=:443"
- "--certificatesresolvers.myresolver.acme.tlschallenge=true"
- "--certificatesresolvers.myresolver.acme.email=your-email@example.com"
- "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
ports:
- "443:443"
- "8080:8080"
volumes:
- "./letsencrypt:/letsencrypt"
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- Edit the
docker-compose.ymlof the self-hosted Sentry and add the followinglabelsto thewebandrelaycontainer, also comment out thenginxcontainer:
web:
<<: *sentry_defaults
...
labels:
- "traefik.enable=true"
- "traefik.http.routers.web.rule=Host(`sentry.example.com`)"
- "traefik.http.routers.web.entrypoints=websecure"
- "traefik.http.routers.web.tls.certresolver=myresolver"
...
relay:
<<: *restart_policy
image: "$RELAY_IMAGE"`
...
labels:
- "traefik.enable=true"
- "traefik.http.routers.relay.rule=Host(`sentry.example.com`) && PathPrefix(`/api/store/`, `/api/{id:[1-9]\\d*/}`)"
- "traefik.http.routers.relay.entrypoints=websecure"
- "traefik.http.routers.relay.tls.certresolver=myresolver"
...
# nginx:
# <<: *restart_policy
# ports:
# - "$SENTRY_BIND:80/tcp"
# image: "nginx:1.22.0-alpine"
# volumes:
# - type: bind
# read_only: true
# source: ./nginx
# target: /etc/nginx
# - sentry-nginx-cache:/var/cache/nginx
# depends_on:
# - web
# - relay
-
Update
sentry/sentry.yml
Setsystem.url-prefixto your new public url of your instance (https://sentry.example.com) -
Edit
sentry/sentry.config.py, enable the SSL/TLS settings -
Now restart Sentry:
$ docker compose down && docker compose up -d -
Start Traefik:
$ docker compose up -d