Publish: 2017-05-08 | Modify: 2017-05-08
Gogs is an easy-to-use self-hosted Git service. Compared to the bulky GitLab, Gogs is more lightweight and requires fewer resources. You can even install it on an Arm-based Raspberry Pi. The installation process of Gogs is also much simpler than GitLab, making it more suitable for personal or small team use.
When creating the database, it is recommended to grant access to the address 127.0.0.1
and grant all permissions to databases starting with the username (username_%). The screenshot below demonstrates this using phpMyAdmin.
# 64-bit binary installation package
wget http://7d9nal.com2.z0.glb.qiniucdn.com/0.11.4/linux_amd64.tar.gz
# Unpack
tar -zxvf linux_amd64.tar.gz
# Enter the installation directory
cd gogs
# Run Gogs, and that's it
./gogs web
# Allow port through firewall (IPtables)
/sbin/iptables -I INPUT -p tcp --dport 3000 -j ACCEPT
service iptables save
service iptables restart
Enter the above commands, allow port 3000 through the firewall, and if there are no errors, access http://IP:3000 to start the installation. Pay attention to the database configuration, as mentioned in the previous step, otherwise, the connection may fail.
Isn't it inconvenient to always use http://IP:3000? You can use a reverse proxy to achieve domain access. Below is a personal reverse proxy configuration (with HTTPS enabled), usually added to vhost/xxx.conf
, and then restart Nginx.
server {
listen 443 ssl http2; # Listen on port 443 and enable HTTP/2
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Allowed protocols
# SSL certificate paths
ssl_certificate /data/ssl/xiaoz.top/xiaoz.top.pem;
ssl_certificate_key /data/ssl/xiaoz.top/xiaoz.top.key;
server_name code.xiaoz.top;
charset utf-8,gbk;
location / {
proxy_pass http://localhost:3000;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
# 301 redirect, redirect from http to https
server {
listen 80;
server_name code.xiaoz.top;
rewrite ^(.*) https://code.xiaoz.top$1 permanent;
}
Note that if you enable HTTPS, please modify custom/conf/app.ini
and change ROOT_URL
to the HTTPS address.
Installing Gogs is very simple (assuming you already have Linux knowledge), and the official documentation is also very detailed. GitHub is undoubtedly an excellent third-party git repository, but private repositories on GitHub are part of a paid service, and there are various issues with using it in China. If you are interested, you can try setting up Gogs yourself.
I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.