Gitea Self-Hosted Git Server on Linux with HTTPS and Backups
Platform

Gitea Self-Hosted Git Server on Linux with HTTPS and Backups

  • Author :Liam K.
  • Date :August 3, 2026
  • Time :18 minutes

Gitea is a lightweight, self-hosted Git service that feels familiar if you already use GitHub or GitLab. It runs well on a single VPS, supports issues and pull requests, and stays lean enough for teams that do not need a full DevOps platform. This guide installs Gitea behind Nginx with PostgreSQL, HTTPS, and backups you can actually restore.

Prerequisites

  • Ubuntu 22.04+ or Debian 12 with at least 2 CPU and 2 GB RAM
  • Domain DNS A/AAAA records for git.example.com
  • Ports 22, 80, and 443 open; Gitea SSH can use a dedicated port if needed
  • Root or sudo access

Step 1: Create the Gitea System User

bash
sudo adduser --system --shell /bin/bash --gecos 'Git Version Control' --group --disabled-password --home /home/git git
sudo mkdir -p /var/lib/gitea/{custom,data,log}
sudo chown -R git:git /var/lib/gitea/
sudo chmod -R 750 /var/lib/gitea/
sudo mkdir -p /etc/gitea
sudo chown root:git /etc/gitea
sudo chmod 770 /etc/gitea

Step 2: Install PostgreSQL and Create the Database

bash
sudo apt update
sudo apt install -y postgresql postgresql-contrib
sudo -u postgres psql <<'EOF'
CREATE USER gitea WITH PASSWORD 'change-me-strong';
CREATE DATABASE giteadb OWNER gitea;
\q
EOF

Step 3: Download and Install Gitea

bash
GITEA_VERSION=1.22.6
sudo wget -O /usr/local/bin/gitea https://dl.gitea.com/gitea/${GITEA_VERSION}/gitea-${GITEA_VERSION}-linux-amd64
sudo chmod +x /usr/local/bin/gitea
gitea --version

Step 4: Create the systemd Service

bash
sudo tee /etc/systemd/system/gitea.service >/dev/null <<'EOF'
[Unit]
Description=Gitea
After=network.target postgresql.service
Wants=postgresql.service
[Service]
Type=simple
User=git
[...]
Command truncated. Copy to view full command.

Step 5: Initial Web Setup

Open http://YOUR_SERVER_IP:3000 and complete the installer. Choose PostgreSQL, set the database user and password from Step 2, set the domain togit.example.com, and keep HTTP listen on127.0.0.1:3000 after the reverse proxy is in place.

bash
sudo sed -i 's/^HTTP_ADDR.*/HTTP_ADDR = 127.0.0.1/' /etc/gitea/app.ini
sudo systemctl restart gitea

Step 6: Nginx Reverse Proxy with TLS

bash
sudo apt install -y nginx certbot python3-certbot-nginx
sudo tee /etc/nginx/sites-available/gitea >/dev/null <<'EOF'
server {
    listen 80;
    server_name git.example.com;
    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
[...]
Command truncated. Copy to view full command.

Step 7: Backup and Restore

bash
# Daily dump of database + repositories
sudo -u postgres pg_dump giteadb | gzip > /var/backups/giteadb-$(date +%F).sql.gz
sudo tar -czf /var/backups/gitea-data-$(date +%F).tar.gz -C /var/lib/gitea data

# Restore example
gunzip -c /var/backups/giteadb-2026-08-03.sql.gz | sudo -u postgres psql giteadb
sudo tar -xzf /var/backups/gitea-data-2026-08-03.tar.gz -C /var/lib/gitea
sudo chown -R git:git /var/lib/gitea/data
sudo systemctl restart gitea

Production Checklist

  • Bind Gitea to localhost and expose only Nginx and SSH.
  • Rotate the PostgreSQL password and store it in a secrets manager or sealed config.
  • Enable 2FA for admin accounts and restrict registration if the instance is private.
  • Test a restore at least once per quarter before you need it.
  • Monitor disk growth under /var/lib/gitea/data and PostgreSQL.

"A Git server is only trustworthy when the database, repositories, and HTTPS edge are backed up and restorable as one unit."

Technical Author

Technical Author - Liam K.
Liam K.

System administrator and technical writer specializing in server infrastructure, security and deployment. Creating comprehensive guides to help you master server administration.