Programmers

Self hosted Sentry

We're going to set up sentry using docker, nginx, systemd, and certbot

Let's go!
This guide assumes you've already installed Docker, Docker Compose, Nginx, and Certbot .

Start by cloning the repository:

git clone https://github.com/getsentry/self-hosted sentry


You will end up with a folder called sentry

Now run the install script:

./sentry/install.sh


You will be prompted to create an admin user during the installation process.

Systemd
Now we're going to create a systemd service, so that we can easily start sentry automatically on boot.

Move the sentry folder to /etc/sentry

sudo mv ./sentry /etc/sentry



Create the following file:

[Unit]
Description=Sentry server
After=docker.service nginx.service

[Service]
Restart=always
ExecStart=/usr/local/bin/docker-compose -f /etc/sentry/docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose -f /etc/sentry/docker-compose.yml stop

[Install]
WantedBy=multi-user.target



Now we can start the service by calling:

sudo systemctl enable sentry
sudo systemctl start sentry


This will also make sure it starts automatically on boot.

Nginx
Now let's configure nginx
Create the following file:

upstream sentry {
    server 0.0.0.0:9000;
}

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
        root /var/www/sentry.domain.com;
        index index.html index.htm index.nginx-debian.html;

        server_name sentry.yourdomain.com;

        location / {
            proxy_pass        http://localhost:9000;
        }
}



Sentry uses the port 9000 by default, but this can be changed if you're already using that port (see SENTRY_BIND in /etc/sentry/.env)

Then add a symlink:

sudo ln -s /etc/nginx/sites-available/sentry /etc/nginx/sites-enabled/sentry



And then restart nginx service:

sudo systemctl restart nginx


Now go to your domain's DNS settings and add a subdomain and point it to your servers ip-address.

Certbot
You need an SSL certificate, and there is no easier way than using certbot.

Assuming you have certbot installed, run:

sudo certbot --nginx -d sentry.yourdomain.com


Email
Edit /etc/sentry/sentry/config.yml and you'll see SMTP configuration in the comments. Just fill in your own values, then restart the sentry service, and you should be good to go.


That's pretty much it!

Sources
https://theappsguy.dev/setting-up-sentry-self-hosted