效果預覽:gitfan.clubmysql
adduser git
passwd git # 輸入密碼
su git
複製代碼
訪問官網下載最新編譯好的二進制包,我的以爲這是最省事最方便的方法。linux
wget http://7d9nal.com2.z0.glb.qiniucdn.com/0.11.34/linux_amd64.tar.gz
tar zxvf linux_amd64.tar.gz
cd gogs
./gogs web -port 10086 # 啓動應用,指定端口,也能夠不指定用默認80
複製代碼
瀏覽器訪問上一步啓動的地址:http://localhost:10086/nginx
./custom/conf/app.ini
後重啓應用nohup ./gogs web >> /your/path/to/save/nohup.out 2>&1 &
複製代碼
這時,你已經基本搭建好Gogs,若是局域網內使用能夠到此爲止,但若是須要部署上線,請繼續往下看。git
假設你已經配置好DNS解析。github
執行命令vi ./custom/conf/app.ini
,找到[server]
內容:web
[server]
DOMAIN = gitfan.club
HTTP_PORT = 10086
ROOT_URL = http://gitfan.club/
DISABLE_SSH = false
SSH_PORT = 22
START_SSH_SERVER = true
OFFLINE_MODE = false
複製代碼
在/etc/nginx/conf.d/
增長gitfan.conf
文件,配置如下內容:sql
server {
server_name gitfan.club;
listen 80;
client_max_body_size 5G; # 突破上傳大文件限制
location / {
proxy_pass http://localhost:10086;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
}
}
複製代碼
而後啓動nginx:數據庫
systemctl start nginx.service
複製代碼
這時候已經能夠訪問了。centos
衆所周知,網站支持https是大勢所趨,如今咱們要把站點升級到https。我採用的是免費的DV證書服務Let's Encrypt,有效期是3個月,過時後須要續簽。瀏覽器
git clone https://github.com/certbot/certbot.git
cd certbot
chmod +x letsencrypt-auto
./letsencrypt-auto certonly --webroot -w /home/git/gogs/public -d gitfan.club
複製代碼
此時,生成的證書存放在/etc/letsencrypt/live/gitfan.club/
裏,而後配置nginx監聽443端口。
# /etc/nginx/conf.d/gitfan.conf
server {
server_name gitfan.club;
listen 443;
ssl on;
ssl_certificate /etc/letsencrypt/live/gitfan.club/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/gitfan.club/privkey.pem;
client_max_body_size 5G;
location / {
proxy_pass http://localhost:10086;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
}
}
複製代碼
假如須要把www.gitfan.club
和gitfan.club
都強制跳轉https,須要在gitfan.conf
文件增長配置:
server {
listen 80;
server_name gitfan.club www.gitfan.club;
return 301 https://gitfan.club$request_uri;
}
複製代碼
可能你還須要設置防火牆來增長服務器安全性,centos自帶的firewall-cmd支持設置開放端口:
systemctl start firewalld.service
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload
firewall-cmd --list-ports # 查看端口是否設置成功
複製代碼
若是我想修改頁面模板怎麼辦?
答:參考這裏,在custom/templates/inject/
增長模板文件。
若是我想中止Gogs服務怎麼辦?
答:ps -ef|grep gogs
找到進程ID,而後kill -9 進程ID
。