效果预览: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
。