架设Git服务器
参考链接:服务器上的 Git - 架设服务器
Git - Smart HTTP
我们一般通过 SSH 进行授权访问,通过 git:// 进行无授权访问,但是还有一种协议可以同时实现以上两种方式的访问。 设置 Smart HTTP 一般只需要在服务器上启用一个 Git 自带的名为 git-http-backend 的 CGI 脚本。 该 CGI 脚本将会读取由 git fetch 或 git push 命令向 HTTP URL 发送的请求路径和头部信息,来判断该客户端是否支持 HTTP 通信(不低于 1.6.6 版本的客户端支持此特性)。 如果 CGI 发现该客户端支持智能(Smart)模式,它将会以智能模式与它进行通信,否则它将会回落到哑(Dumb)模式下(因此它可以对某些老的客户端实现向下兼容)。
- 举个例子
$ git clone git@gitserver:/opt/git/project.git
这个是用ssh实现的远程仓库操作$ git clone https://www.ailearn666.com/git/project.git
这个可以用Git SmartHTTP实现这种效果
push的操作认证
参考链接:在centos中搭建基于smart http的git server
- 打开刚刚创建的project.git仓库为config添加如下配置
输入命令:cd /opt/git/project.git
- 打开config文件添加如下内容
完成后保存并退出[http] receivepack = true
配置Apache2 HTTPS端口
# vim /etc/apache2/ports.conf
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf
#Listen 80
<IfModule ssl_module>
#Listen 443
Listen 1000
</IfModule>
<IfModule mod_gnutls.c>
#Listen 443
Listen 1000
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
- 这里我屏蔽了默认的80 HTTP端口,433 HTTPS端口
- 这里1000端口是我用来搭建Smart HTTP的
配置Apache2 VirtualHost
# vim /etc/apache2/sites-enabled/default-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:1000>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
LogLevel info ssl:info
ErrorLog ${APACHE_LOG_DIR}/git_http_error.log
CustomLog ${APACHE_LOG_DIR}/git_http_access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/1745435_www.ailearn666.com_public.crt
SSLCertificateKeyFile /etc/apache2/ssl/1745435_www.ailearn666.com.key
SSLCertificateChainFile /etc/apache2/ssl/1745435_www.ailearn666.com_chain.crt
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
SetEnv GIT_PROJECT_ROOT /home/data/git/
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ /usr/lib/git-core/git-http-backend/
<Directory "/usr/lib/git-core*">
Options ExecCGI Indexes
Order allow,deny
Allow from all
Require all granted
</Directory>
#<LocationMatch "^/git/.*/git-receive-pack$">
# AuthType Basic
# AuthName "Git Access"
# AuthUserFile /etc/apache2/git-conf/git-team.htpasswd
# Require valid-user
#</LocationMatch>
<Location />
AuthType Basic
AuthName "Git Access"
AuthUserFile /etc/apache2/git-conf/git-team.htpasswd
Require valid-user
</Location>
</VirtualHost>
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
- 配置完 重启apache2
# service apache2 restart