git --bare init /hhsailors/git/ --shared
chown -R www-data:www-data /hhsailors/git
vim /etc/apache2/sites-available/git
SetEnv GIT_PROJECT_ROOT /hhsailors/git
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ /usr/lib/git-core/git-http-backend/
#ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
<LocationMatch "^/git/.*/git-receive-pack$">
#push needs auth
AuthType Basic
AuthName "Git Access"
#Require group committers
Require valid-user
AuthUserFile /hhsailors/git.passwd
</LocationMatch>
cd /etc/apache2/
cd sites-enabled/
ln -s ../sites-available/git 001-git
===== 局域网用用的话,到这里就OK了,如果要远程使用,最好还需要启用https ====
enable ssl:
a2enmod ssl
openssl req -x509 -newkey rsa:1024 -keyout /etc/ssl/private/hhsailors.key -out /etc/ssl/certs/hhsailors.pem -nodes -days 9999
#or put keyout and out in the same file by pass the same parameter. in this case we needs no SSLCertificateKeyFile.
vim sites-enabled/001-git
<IfModule mod_ssl.c>
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/ssl/certs/hhsailors.pem
SSLCertificateKeyFile /etc/ssl/private/hhsailors.key
</VirtualHost>
</IfModule>
/etc/init.d/apache2 reload
用https时候客户端可能报证书错误:
git config --global http.sslVerify false
or
export GIT_SSL_NO_VERIFY=true
see http://stackoverflow.com/questions/3777075