How To Install Gogs Git Server on Ubuntu 20.04

Gogs get attention because it’s fast and only a single binary go application which is make update/upgrade really simple. Gogs runs anywhere Go can be compiled to Windows, Mac, Linux, ARM, etc.

– Ubuntu 20.04
– Domain name
– Basic CLI knowledge

Setup DNS Record

For git hosting HTTPS is mandatory because you don’t want someone snooping on your traffic. Setup the DNS for your domain, in my case I setup to the server IP.
setup sub domain record

Install Git

Install the latest git version supported by Debian 10.

sudo apt install git -y

Debian 10 setup git

Download Gogs

Download Gogs from release page

wget -O gitea

gogs download latest version
extract file we just download earlier

tar zxvf gogs_0.12.3_linux_amd64.tar.gz

run the gogs for the first time.

Gogs Systemd Service

Create a systemd service file to run the Gogs in the background and every time system booting. Create /lib/systemd/system/gogs.service file copy following lines

ExecStart=/home/atetux/gogs/gogs web
Environment=USER=atetux HOME=/home/atetux GOGS_WORK_DIR=/home/atetux

replace atetux with your own username/login shell.
Enable Gogs on boot

sudo systemctl enable gogs

Run the Gogs

sudo systemctl restart gogs

check if services run correctly

sudo systemctl status gogs

atetux log files

Configure Gogs

open http://[IP-SERVER]:3000 on browser
gogs install
Change following value

Database Type : SQLite3
Domain :
Run user : USERNAME

scroll down then click Install Gogs. Dont worry when the webpage redirect to http://localhost:3000/user/login
cant access localhost 3000
we’ll use nginx as reverse proxy later to handle that.

Install Certbot Letsencrypt

Install Nginx

Since to able to run on port 80/443 Gogs need to run as root, which is a security nightmare. Instead, we’ll use Nginx as a reverse proxy for Gogs, we’ll mapping the port 3000 to our subdomain, for this case

sudo apt install nginx -y

Install Certbot

sudo apt install certbot python3-certbot-nginx -y

Setup temporary server block for

sudo nano /etc/nginx/sites-enabled/

copy the lines below to /etc/nginx/sites-enabled/

server {
    listen 80;

nginx server block

Generate SSL for Gogs

sudo certbot certonly --nginx -d gogs.DOMAIN --agree-tos -m

When asked :
We’d like to send you email about our work encrypting the web, EFF news, campaigns, and ways to support digital freedom. Enter N
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access. Enter 2

Setup Gogs Reverse Proxy

Open the nginx config file on /etc/nginx/sites-enabled/, replace all lines with

server {
    listen 80;
    return 301 https://$server_name$request_uri;
server {
    listen 443 ssl;
    ssl_certificate /etc/letsencrypt/live/;
    ssl_certificate_key /etc/letsencrypt/live/;
    location / {
        proxy_set_header X-Real-IP $remote_addr;

gogs nginx reverse proxy
Verify nginx

sudo nginx -t

nginx test okay

sudo systemctl reload nginx

Enable nginx on boot

sudo systemctl enable nginx

gogs installed correctly

Leave a Comment