gogs配置https
gogs配置https
过程,给gogs设置https,当然前提有自己的域名,自己的证书。
并且本文解决了
error: RPC failed; HTTP 413 curl 22 The requested URL returned error: 413
这个错误。
第一步,安装http的gogs
到官网下载,解压,然后其实无需安装,直接就作为程序跑。
最开始,执行 ./gogs web
然后开启防火墙3000,打开浏览器 ip:3000/
进行一系列配置。填ip就行。
最后,为方便使用,做个服务。
安装 systemctl的服务,我的服务器是centos 8
vi /usr/lib/systemd/system/gogs.service
我这里示范的是错误的用法,正确应该自己建立用户。
这里额外说一句,如果您打算采用ssh形式网址的git仓库,请绝对不要使用root用户,因为会遇到一些问题,gogs会自己修改认证文件。
如果像我这样用 http 或 https 域名的仓库,就关系不大。
[Unit]
Description=Gogs
After=syslog.target
After=network.target
# After=mariadb.service mysqld.service postgresql.service memcached.service redis.service
[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
Type=simple
User=root
Group=root
WorkingDirectory=/root/temp/gogs
ExecStart=/root/temp/gogs/gogs web
Restart=always
Environment=USER=root HOME=/root
ProtectSystem=full
PrivateDevices=yes
PrivateTmp=yes
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target
第2步: nginx配置
首先在第一步确保gogs能正常运行,这时我们才修改https,做的工作比较多。
现在要先去域名配置,解析。
server {
listen 80;
# 血泪教训,一定要加
client_max_body_size 100m;
server_name gog.xxx.com;
location / {
rewrite ^ https://gog.xxx.com$request_uri? permanent;
}
}
server {
listen 443 ssl;
# 血泪教训,一定要加
client_max_body_size 100m;
server_name gog.xxx.com;
ssl_certificate /etc/nginx/pem/xxx.com.pem;
ssl_certificate_key /etc/nginx/pem/xxx.com.key;
location / {
proxy_pass http://localhost:3000;
}
}
第3步 gogs 的配置
修改 程序目录/custom/conf/app.ini
DOMAIN 显示在 ssh仓库的地址。
EXTERNAL_URL显示在 http仓库的地址。
[server]
DOMAIN = gog.xxx.com
HTTP_PORT = 3000
EXTERNAL_URL = https://gog.xxx.com/
DISABLE_SSH = false
SSH_PORT = 22
START_SSH_SERVER = false
OFFLINE_MODE = false
第4步:关闭防火墙
现在立刻完全关闭3000,
然后下载地址变成这样:
git clone https://gog.xxx.com/myuser/myproject.git
这样就安全了!
第5步,总结:
1、git仓库地址必须改变成使用域名,且使用https
2、在浏览器登录 gogs 的管理控制台:使用 gog.xxx.com,就行。
3、解决了 error: RPC failed; HTTP 413 curl 22 The requested URL returned error: 413 这个错误。通过nginx的配置解决的。
本作品采用《CC 协议》,转载必须注明作者和本文链接