Install Gogs on Ubuntu 18 server with MariaDB and Nginx

Install

Install requirements:

apt install nginx mariadb-server mariadb-client git certbot python-certbot-nginx

Configure MariaDB:

mysql_secure_installation

Add user for gogs:

adduser --disabled-login git

Change user to git:

su - git

Download binary from [Gogs site][1] according to your architecture:

wget [URL]

Extarct the tar file:

tar -xf gogs*

Go back to root:

exit

Copy the Gogs’s systemd unit file to an apropriate folder, eg.: /etc/systemd/system/:

cp /home/git/gogs/scripts/systemd/gogs.service /etc/systemd/system/

Refresh the unit files:

systemctl daemon-reload

Enable Gogs:

systemctl enable gogs

Gogs binary comes with an sql dump to create and config the database for Gogs:

mysql -u root -p < /home/git/gogs/scripts/mysql.sql

Login to MariaDB:

mysql -u root -p

Check databases, gogs should be there:

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| gogs               | <-------
| information_schema |
| mysql              |
| performance_schema |
+--------------------+

Create user:

create user '[USER]'@'localhots' identified by '[PASSWORD]';

Grant privileges for the new user:

grant all on gogs.* to '[USER]'@'localhost' identified by '[PASS]' with grant option;
flush privileges;
exit;

Nginx

Get an SSL certificate from Let’s Encrypt:

certbot certonly -d git.example.com

An example code to configure Nginx:

nano /etc/nginx/nginx.conf
server {
    listen 443 ssl;
    listen [::]:443 ssl;
	
    ssl_certificate /etc/letsencrypt/live/git.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/git.example.com/privkey.pem;

	server_name git.example.com;

	location / {
		proxy_pass http://0.0.0.0:3000/;
	}		
}

server {

	listen 80;
	listen [::]:80;

	server_name git.example.com;
    
	return 301 https://$server_name$request_uri;
}

Gogs

Start Gogs service:

systemctl start gogs