公司需要在自己的服务器上部署一个私有的 git 远程仓库,在权衡了市面上的几款开源 git 仓库服务后,我选择了 gogs,无他,部署简单,资源占用低。花了大概一个半天的时间搭建好了,综合了 gogs 官网的文档及网络上的资料,这里做一个简单的记录,保证可用。
下载 gogs 压缩包,解压,在解压下的目录,新建 log 文件夹和 conf 文件夹: 在里面分别新建空白的 txt 文件和 app.ini 文件备用。 在 app.ini 文件中写入自己的配置: 其中 RUN_USER 的值由运行命令:
echo %COMPUTERNAME%获得,显示的是什么,就在它之后加一个$
下载 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,解压,cd 到目录下,输入命令:
start nginx (输入这一句会看到一个黑窗一闪而过) tasklist /fi "imagename eq nginx.exe"可以看到 接下来修改 nginx 的配置,在 conf 文件夹下的 nginx.conf 文件,在 server 下添加 listen,server_name,以及配置 location 即可。 修改完配置,可以输入命令来查看配置文件中的语法是否有错误: 没问题的话,重启 nginx: 同样的,nginx 也可以配置为 windows 的服务。
在使用的过程中发现传输太大的文件,git 会传不上去,这是问题出在 nginx 那里,它限制了传输的大小,改一下相关配置即可。