1.安装httpd和git
yum install git httpd git-core
2.创建git仓库
mkdir -p /git
cd /git
git init --bare test.git
# 设置权限,注意如果后续添加了新的仓库,要重新添加权限
chown -R apache:apache .
3.创建账号
htpasswd -m -c /git/passfile user1
htpasswd -m /git/passfile user2
# 修改git-team.htpasswd文件的所有者与所属群组
chown apache:apache /etc/httpd/conf.d/git-team.htpasswd
# 设置git-team.htpasswd文件的访问权限
chmod 640 /etc/httpd/conf.d/git-team.htpasswd
4.设置apache,使其请求转发到git-cgi
vi /etc/httpd/conf/httpd.conf
# 80端口交给nginx管理,这里需要配置Listen和ServerName
Listen = 86
ServerName = 127.0.0.1:86
<VirtualHost *:86>
# ServerName 因为还需要nginx转一下,所以这里不需要
SetEnv GIT_HTTP_EXPORT_ALL
SetEnv GIT_PROJECT_ROOT /git
# ScriptAlias是将以/git/开头的访问路径映射至git的CGI程序git-http-backend
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
<Location /git>
AuthType Basic
AuthName "Git"
AuthUserFile /git/passfile
Require valid-user
</Location>
</VirtualHost>
- 重启或启动apache
systemctl restart httpd.service
6.nginx增加配置
vim /usr/local/nginx/conf/nginx.conf
location /git/ {
# 注意git后面的/不能少,https://blog.csdn.net/zhongzh86/article/details/70173174
proxy_pass http://127.0.0.1:86/git/;
# 上传大小100兆
client_max_body_size 100m;
}
7.重启nginx
nginx -s reload
8.使用
git clone http://username:password@xxx.xxx.xxx.xxx/git/test.git
另,如何出现push权限被禁止的话,需要关闭selinux
//查看selinux状态
getenforce
//临时关闭selinux
setenforce 0
//永久关闭selinux
vi /etc/sysconfig/selinux
//将SELINUX=enforcing改为SELINUX=disabled
//重启服务器即可