Windows server 部署 gogs 服务简记

公司需在服务器部署私有 git 远程仓库,经权衡选择部署简单、资源占用低的 gogs。本文记录了在 Windows server 上部署 gogs 服务的过程,包括安装 gogs、用 nssm 将其注册成服务、使用 nginx 转发请求,还提及使用中传输大文件的问题及解决办法。

Windows server 部署 gogs 服务简记

公司需要在自己的服务器上部署一个私有的 git 远程仓库,在权衡了市面上的几款开源 git 仓库服务后,我选择了 gogs,无他,部署简单,资源占用低。花了大概一个半天的时间搭建好了,综合了 gogs 官网的文档及网络上的资料,这里做一个简单的记录,保证可用。

安装 gogs

下载 gogs 压缩包,解压,在解压下的目录,新建 log 文件夹和 conf 文件夹:
在这里插入图片描述
在这里插入图片描述
在里面分别新建空白的 txt 文件和 app.ini 文件备用。
在 app.ini 文件中写入自己的配置:
在这里插入图片描述
其中 RUN_USER 的值由运行命令:

echo %COMPUTERNAME%

获得,显示的是什么,就在它之后加一个$

nssm

下载 nssm,nssm 的作用是将 gogs 注册成 windows 服务,解压,cd 到目录下,运行:

nssm install gogs

会弹出一个弹窗,弹窗中的设置参考 gogs 官方文档:

Use NSSM
Get the nssm.exe needed for your machine (32 or 64 bit; they’re packaged together in Iain’s zip file), and place it in a directory that is in (or will be added to) your %PATH% environment variable.
Open a command line as administrator and do following command to configure Gogs as a service:
C:>nssm install gogs
“NSSM service installer” will appear. Configure it as follows:
Application tab:
* Path: C:\gogs\gogs.exe
* Startup directory: C:\gogs
* Arguments: web
在这里插入图片描述
Details tab:
* Display name: Gogs
* Description: A painless self-hosted Git service.
* Startup type: Automatic (Delayed Start)
Note that we’ve chosen delayed start, so that the service will not impact the early boot time. Gogs will start two minutes after the non-delayed services.
在这里插入图片描述
I/O tab:
* Output (stdout): C:\gogs\log\gogs-nssm.txt
* Error (stderr): C:\gogs\log\gogs-nssm.txt
That will capture all text output that you would normally receive from Gogs on the command line console, and log it to that file instead.
在这里插入图片描述
File rotation tab:
* Check: Rotate files
* Restrict rotation to files bigger than: 1000000 bytes
在这里插入图片描述
Environment tab:
* Environment variables: PATH=%PATH%;C:\gogs;C:\Program Files (x86)\Git\bin
That is a guarantee that both gogs.exe and git.exe will be on the Gogs service’s path variable during runtime.
在这里插入图片描述
Click “Install service”, and you should be confirmed that it succeeded.

成功后,可以在服务中看到 gogs 服务:
在这里插入图片描述

nginx

需要转发请求,我选择使用 nginx。下载安装 nginx,解压,cd 到目录下,输入命令:

start nginx   (输入这一句会看到一个黑窗一闪而过)
tasklist /fi "imagename eq nginx.exe"

可以看到
在这里插入图片描述
接下来修改 nginx 的配置,在 conf 文件夹下的 nginx.conf 文件,在 server 下添加 listen,server_name,以及配置 location 即可。
修改完配置,可以输入命令来查看配置文件中的语法是否有错误:
在这里插入图片描述
没问题的话,重启 nginx:
在这里插入图片描述
同样的,nginx 也可以配置为 windows 的服务。

后记:

在使用的过程中发现传输太大的文件,git 会传不上去,这是问题出在 nginx 那里,它限制了传输的大小,改一下相关配置即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值