mirror of
http://git.nowherejezfoltodf4jiyl6r56jnzintap5vyjlia7fkirfsnfizflqd.onion/nihilist/selfhosting-blogposts.git
synced 2025-05-16 12:16:59 +00:00
290 lines
8.2 KiB
Markdown
290 lines
8.2 KiB
Markdown
---
|
|
search:
|
|
exclude: true
|
|
---
|
|
# Gitea Setup (nginx, postgresql, debian10)
|
|
|
|

|
|
|
|
Before we start, you will need a Debian 10 VPS (you can get one on digitalocean for example), if you prefer to use your own self hosted server, make sure that port 80 and 443 are correctly port forwarded so that the public ip points to the server and not the router. Once that's done, go and ssh into your debian 10 server.
|
|
|
|
## **Initial Setup**
|
|
|
|
|
|
adduser --system --shell /bin/bash --group --disabled-password --home /home/git git
|
|
wget -O /usr/local/bin/gitea https://dl.gitea.io/gitea/1.12.5/gitea-1.12.5-linux-amd64
|
|
chmod +x /usr/local/bin/gitea
|
|
./gitea
|
|
|
|
mkdir -p /var/lib/gitea/{custom,data,indexers,public,log}
|
|
chown git:git /var/lib/gitea/{data,indexers,log}
|
|
chmod 750 /var/lib/gitea/{data,indexers,log}
|
|
mkdir /etc/gitea
|
|
chown root:git /etc/gitea
|
|
chmod 770 /etc/gitea
|
|
|
|
wget https://raw.githubusercontent.com/go-gitea/gitea/master/contrib/systemd/gitea.service
|
|
nano gitea.service
|
|
|
|
|
|
|
|
Now in nano, you need to add the **After=postgresql.service** line, once that's done, hit CTRL+S to save, and CTRL+X to exit.
|
|
|
|

|
|
|
|
|
|
cp gitea.service /etc/systemd/system/
|
|
systemctl enable gitea
|
|
|
|
|
|
|
|
Next we'll setup postgresql:
|
|
|
|
|
|
apt-get -y install apt-transport-https lsb-release ca-certificates curl gnupg -y
|
|
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
|
|
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
|
|
|
|
apt update -y
|
|
apt install postgresql-13 -y
|
|
|
|
su -c "psql" - postgres
|
|
CREATE ROLE gitea WITH LOGIN PASSWORD 'gitea';
|
|
CREATE DATABASE giteadb WITH OWNER gitea TEMPLATE template0 ENCODING UTF8 LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';
|
|
exit
|
|
|
|
|
|
Next we'll configure Nginx:
|
|
|
|
|
|
apt install nginx -y
|
|
|
|
|
|
|
|
Here we're going to use [DuckDNS](https://www.duckdns.org/) because it is a free way to get a domain name, but if you have your own paid domain name, you can use it too.
|
|
|
|
 
|
|
|
|
Once that's done, we will setup acme.sh to get a free letsencrypt certificate:
|
|
|
|
|
|
apt install socat -y
|
|
wget -O - https://get.acme.sh | sh
|
|
source ~/.bashrc
|
|
systemctl stop nginx
|
|
acme.sh --issue --standalone -d ech2.duckdns.org -k 4096
|
|
systemctl start nginx
|
|
|
|
|
|
|
|

|
|
|
|
Once this is done, download the nginx configuration for gitea:
|
|
|
|
|
|
wget https://blog.nowhere.moe/servers/Gitea/gitea.conf -O /etc/nginx/sites-enabled/gitea.conf
|
|
nano /etc/nginx/sites-enabled/gitea.conf
|
|
cat /etc/nginx/sites-enabled/gitea.conf
|
|
|
|
#if you're doing a gitea setup behind a reverse nginx proxy, it would look like so:
|
|
server {
|
|
listen 80;
|
|
listen [::]:80;
|
|
server_name git.nowhere.moe;
|
|
|
|
location / {
|
|
client_max_body_size 1000m;
|
|
proxy_pass http://localhost:3000;
|
|
}
|
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
client_max_body_size 5000m;
|
|
}
|
|
|
|
# and then on the main reverse nginx proxy you would edit the ssl certificates:
|
|
|
|
|
|

|
|
|
|
Once you're done editing your domain name inside the config, hit CTRL+S to save, and CTRL+X to exit nano and reload nginx:
|
|
|
|
|
|
nginx -t
|
|
nginx -s reload
|
|
apt install git
|
|
systemctl start postgresql gitea
|
|
|
|
|
|
|
|
Once that's done simply browse to your website and set it up after clicking the "register button":
|
|
|
|
 
|
|
|
|
Here in this example i intend to use gitea for my own use, but if you want to have multiple users here, you can untick "disable self registration", If it is for only one user, tick it and create the administrator user at the bottom of the page:
|
|
|
|

|
|
|
|
Once that's done, hit "install gitea" and then we go back into the ssh root shell to change the directories permissions:
|
|
|
|
|
|
chmod 750 /etc/gitea
|
|
chmod 644 /etc/gitea/app.ini
|
|
|
|
|
|
|
|

|
|
|
|
And there you have it!
|
|
|
|
## **Creating your first gitea repository**
|
|
|
|
Just like in github, click the "+" at the top right corner:
|
|
|
|

|
|
|
|
From here you can clone the repository on your local machine:
|
|
|
|
|
|
[ 192.168.100.1/24 ] [ /dev/pts/10 ] [~/Documents/Github]
|
|
→ git clone https://ech2.duckdns.org/nothing/mycoolrepo
|
|
|
|
|
|
|
|
Use the administrator's gitea credentials to clone the repository if you set it to private, and you're done! You can now start editing your self-hosted repository.
|
|
|
|
To customise the default gitea theme you can do the following, it comes up with arc-green as an alternative dark theme out of the box, or you can just use your own:
|
|
|
|
|
|
echo '[ui]' >> /etc/gitea/app.ini
|
|
echo 'THEMES = gitea,arc-green,lain' >> /etc/gitea/app.ini
|
|
echo 'DEFAULT_THEME = lain' >> /etc/gitea/app.ini # put 'arc-green' there instead for the default dark theme
|
|
|
|
cd /var/lib/gitea/custom
|
|
git clone https://git.void.yt/nothing/gitea-lain-template .
|
|
|
|
|
|
chown git:git /var/lib/gitea/{data,indexers,log}
|
|
chmod 750 /var/lib/gitea/{data,indexers,log}
|
|
|
|
chown root:git /etc/gitea
|
|
chmod 770 /etc/gitea
|
|
|
|
chmod 750 /etc/gitea
|
|
chmod 644 /etc/gitea/app.ini
|
|
|
|
systemctl restart postgresql gitea
|
|
|
|
|
|
|
|
To automatically update gitea:
|
|
|
|
|
|
root@gitea:~# apt install python3-pip
|
|
root@gitea:~# apt install mlocate -y ; updatedb ; locate settings.ini
|
|
root@gitea:~# pip3 install gitea-auto-update
|
|
|
|
root@gitea:/etc/gitea# vim settings.ini
|
|
root@gitea:/etc/gitea# cat settings.ini
|
|
[Gitea]
|
|
site=https://git.nowhere.moe/api/v1/version
|
|
apiUrl=https://api.github.com/repos/go-gitea/gitea/releases/latest
|
|
system=linux-amd64
|
|
file=/usr/local/bin/gitea
|
|
tmpDir=/tmp/
|
|
buildFromSource=
|
|
sourceDir=
|
|
logFile=update.log
|
|
root@gitea:/etc/gitea# gitea-auto-update --settings=/etc/gitea/settings.ini
|
|
update successfully
|
|
root@gitea:/etc/gitea# crontab -e
|
|
|
|
# m h dom mon dow command
|
|
0 0 * * * /usr/local/bin/gitea-auto-update --settings=/etc/gitea/settings.ini
|
|
|
|
:wq
|
|
|
|
|
|
|
|
With this setup, gitea will upgrade itself everyday at midnight. Here is my final **/etc/gitea/app.ini** file:
|
|
|
|
|
|
APP_NAME = Nihilism Gitea: Git with a cup of tea
|
|
RUN_USER = git
|
|
RUN_MODE = prod
|
|
|
|
[oauth2]
|
|
JWT_SECRET = dasljdashdaslhdas
|
|
|
|
[security]
|
|
INTERNAL_TOKEN = daojpoawdjpoaj
|
|
INSTALL_LOCK = true
|
|
SECRET_KEY = dapijpsadpdsajpodasj
|
|
|
|
[database]
|
|
DB_TYPE = postgres
|
|
HOST = 127.0.0.1:5432
|
|
NAME = giteadb
|
|
USER = kljdhaslhjkdas
|
|
PASSWD = jahsdhdshjsadl
|
|
SCHEMA =
|
|
SSL_MODE = disable
|
|
CHARSET = utf8
|
|
PATH = /var/lib/gitea/data/gitea.db
|
|
|
|
[repository]
|
|
ROOT = /home/git/gitea-repositories
|
|
|
|
[repository.upload]
|
|
; Max number of files per upload. Defaults to 5
|
|
MAX_FILES = 500000000000
|
|
|
|
[server]
|
|
SSH_DOMAIN = localhost
|
|
DOMAIN = git.nowhere.moe
|
|
HTTP_ADDR = 127.0.0.1
|
|
HTTP_PORT = 3000
|
|
ROOT_URL = https://git.nowhere.moe/
|
|
DISABLE_SSH = false
|
|
SSH_PORT = 22
|
|
LFS_START_SERVER = true
|
|
LFS_CONTENT_PATH = /var/lib/gitea/data/lfs
|
|
LFS_JWT_SECRET = aidsjisajdlasjildsa
|
|
OFFLINE_MODE = true
|
|
|
|
[mailer]
|
|
ENABLED = false
|
|
|
|
[service]
|
|
REGISTER_EMAIL_CONFIRM = false
|
|
ENABLE_NOTIFY_MAIL = false
|
|
DISABLE_REGISTRATION = false
|
|
ALLOW_ONLY_EXTERNAL_REGISTRATION = false
|
|
ENABLE_CAPTCHA = false
|
|
REQUIRE_SIGNIN_VIEW = true
|
|
DEFAULT_KEEP_EMAIL_PRIVATE = true
|
|
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
|
|
DEFAULT_ENABLE_TIMETRACKING = true
|
|
NO_REPLY_ADDRESS = noreply.nowhere.moe
|
|
|
|
[picture]
|
|
DISABLE_GRAVATAR = true
|
|
ENABLE_FEDERATED_AVATAR = false
|
|
|
|
[openid]
|
|
ENABLE_OPENID_SIGNIN = true
|
|
ENABLE_OPENID_SIGNUP = false
|
|
|
|
[session]
|
|
PROVIDER = file
|
|
|
|
[log]
|
|
MODE = file
|
|
LEVEL = info
|
|
ROOT_PATH = /var/lib/gitea/log
|
|
|
|
[ui]
|
|
THEMES = gitea,arc-green
|
|
DEFAULT_THEME = arc-green
|
|
|
|
|