Skip to main content

Gitea

Want a place to store your source code / configurations you've made? Look into hosting a git server, in this case, Gitea!

These instructions will walk you through installing Gitea, and enabling access behind Caddy (assuming you've used the guide in this documentation).

Install Gitea

Download the Executable

wget -O gitea https://dl.gitea.com/gitea/1.22.4/gitea-1.22.4-linux-amd64
chmod +x gitea

Prepare your Environment

It's best practice to create a new user for each service you run:

adduser \
   --system \
   --shell /bin/bash \
   --gecos 'Git Version Control' \
   --group \
   --disabled-password \
   --home /home/git \
   git

Then you should create the required directory structure:

mkdir -p /var/lib/gitea/{custom,data,log}
chown -R git:git /var/lib/gitea/
chmod -R 750 /var/lib/gitea/
mkdir /etc/gitea
chown root:git /etc/gitea
chmod 770 /etc/gitea

/etc/gitea is temporarily set with write permissions for user git so that the web installer can write the configuration file. After the installation is finished, it is recommended to set permissions to read-only using:

chmod 750 /etc/gitea
chmod 640 /etc/gitea/app.ini

Now you should copy the gitea executable to a global location:

cp gitea /usr/local/bin/gitea

And now you should probably turn Gitea into a system service. Copy the sample gitea.service to /etc/systemd/system/gitea.service and modify it with your favorite text editor.

And then enable & start the service:

sudo systemctl enable gitea --now

Just like that, you've installed Gitea, albeit hidden away on its' own port. To start setting up Gitea, you can navigate to http://machine.ip:3000 or check out the section below to put it on a subdomain behind Caddy before you get any further.

Put it behind Caddy

With the modular Caddy layout set up, we can simply create a new file:

# /etc/caddy/sites-available/git.example.nx3.caddy

https://git.example.nx3 {
  reverse_proxy http://127.0.0.1:3000
}

And link/reload Caddy:

sudo ln -s /etc/caddy/sites-available/git.example.nx3.caddy /etc/caddy/sites-enabled/git.example.nx3.caddy
sudo systemctl caddy reload

Now you should be able to access your Gitea instance @ https://git.your.domain, where you'll be prompted to continue with the initial setup if not finished earlier.