Gitea

robots.txt

By default, Gitea doesn’t include a robots.txt file.

My Gitea robots.txt is available here.

Usage

sudo mkdir -p /var/www/gitea-robots.txt/
sudo chown -R $USER:$USER /var/www/gitea-robots.txt/
git clone https://git.lelux.fi/theel0ja/gitea-robots.txt.git /var/www/gitea-robots.txt/

Add a cronjob

30	6	*/3	*	*	cd /var/www/gitea-robots.txt/ && git pull --quiet

nginx.conf

location = /robots.txt {
        root /var/www/gitea-robots.txt;
}

Building

Build-time dependencies

Also, make sure to configure GOPATH for your user.

On Bash, run:

echo "export GOPATH=$HOME/go" >> ~/.bash_profile

# load (source) ~/.bash_profile
source ~/.bash_profile

Download Gitea source code by running:

go get -d -u code.gitea.io/gitea

It should take at maximum few minutes.

Then, move to Gitea source code folder:

cd "$GOPATH/src/code.gitea.io/gitea"

List releases with git tag -l.

At the time of writing, the latest stable version is v1.8.3.

Choose it by running:

git checkout v1.8.3

With git branch -a, you can see you switched to the release.

$ git branch -a
* (HEAD detached at v1.8.3)
  master

Start the build by running:

TAGS="bindata" make generate build

After build, you can try the binary by running:

./gitea web

If it runs without errors, close it by Ctrl+C.

Copy the binary to /usr/local/bin/gitea by running:

sudo cp $GOPATH/src/code.gitea.io/gitea/gitea /usr/local/bin/gitea

Installation

Dependencies

First, make sure Git is installed on your server. You can try this by running:

git --version

Then, create user for Gitea:

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

After creating user account successfully, create folders:

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 /etc/gitea
sudo chown root:git /etc/gitea
sudo chmod 770 /etc/gitea

systemd service

First, download template by running:

curl -L https://raw.githubusercontent.com/go-gitea/gitea/master/contrib/systemd/gitea.service | sudo tee /etc/systemd/system/gitea.service > /dev/null

If your MySQL server runs on the same server, edit the file by running sudo -e /etc/systemd/system/gitea.service. Uncomment the following line:

Requires=mysql.service

Then, start the service by running:

sudo systemctl daemon-reload
sudo systemctl enable --now gitea

To see if Gitea runs successfully, run:

curl -I 127.0.0.1:3000

It should return HTTP/1.1 200 OK.

Nginx configuration

Filename /etc/nginx/sites-available/gitea:

upstream gitea {
        server 127.0.0.1:3000;
}

server {
        # see https://wiki.lelux.fi/certbot and https://wiki.lelux.fi/nginx for listen, SSL configuration, etc.
        # ...
        # ...

        server_name gitea.example.com;

        location / {
                proxy_set_header X-Real-IP  $remote_addr;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_set_header Host $host;

                proxy_pass http://gitea;
        }

        location = /robots.txt {
                root /var/www/gitea-robots.txt;
        }
}

To get robots.txt to work, do steps listed here.

For more Nginx configuration, see certbot and nginx.

Enable Nginx configuration

sudo rm /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/

sudo systemctl restart nginx

After that, open https://gitea.example.com/install in your browser.

Tutorial is going to be continued with MySQL configuration, email server setup, etc.

Update script

Tip: Subscribe to Gitea repository update notifications on UpdateWatch.

Make sure your $GOPATH is correctly set.

cd $GOPATH/src/code.gitea.io/gitea
git pull
echo "Select version"
echo "git checkout vX.X.X && exit"
echo ""
echo ""
git tag -l
bash

# bindata is not recommended here: https://docs.gitea.io/en-us/install-from-source/
TAGS="bindata" make generate build

sudo systemctl stop gitea
sudo cp $GOPATH/src/code.gitea.io/gitea/gitea /usr/local/bin/gitea
sudo systemctl daemon-reload
sudo systemctl start gitea