2017-09-26 34 views
0

大師我怎樣才能使當我們使用HTTP作爲訪問協議

我剛剛發現git的鉤(預接收後接收)不能運行,而這樣做的git推git的/掛鉤/預接收工作通過HTTP,但是這些鉤子可以在通過SSH進行git-push時調用。
這是正確的嗎?
那麼我怎樣才能讓git/hooks /預接受工作,而我們使用HTTP作爲訪問協議?

/// ------------------------------------------ -------------------------------------------------- ----
/// @SERVER
///這是 - 接收後鉤代碼

hello.git $ cat hooks/post-receive 
#!/bin/bash 
while read oldrev newrev ref 
do 
    if [[ $ref =~ .*/master$ ]]; 
    then 
     echo "Master ref received. Deploying master branch to production..." 
     #git --work-tree=/var/www/html --git-dir=/home/demo/proj checkout -f 
    else 
     echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server." 
    fi 
done 

/// ---------------- -------------------------------------------------- ------------------------------
/// @ CLIENT
///這裏git/hooks/post-receive在通過SSH進行git推送時工作。

$ git push 
[email protected]'s password: 
Counting objects: 5, done. 
Delta compression using up to 8 threads. 
Compressing objects: 100% (3/3), done. 
Writing objects: 100% (5/5), 390 bytes | 390.00 KiB/s, done. 
Total 5 (delta 1), reused 0 (delta 0) 
remote: Master ref received. Deploying master branch to production... 
To hostxxx.net:/var/www/html/repo/hello.git 
    a308dbc..82184b8 master -> master 
+0

你用什麼服務器來推送HTTP? – phd

+0

我們爲位於互聯網上的業務設置了一臺服務器,並且由於代理服務器的安全限制,我們必須使用HTTP/HTTPS協議而不是SSH。 那麼請給我任何建議? – zhengfish

+0

是的,但是服務器究竟是什麼?簡單的HTTP服務器肯定不會運行服務器端的鉤子,你需要配置[git-http-backend](https://www.kernel.org/pub/software/scm/git/docs/git-http-backend。 HTML)。 – phd

回答

0

遵循@phd指南,我改進了我的apache2的conf,現在它可以工作。

這裏是完整的apache2 conf供您參考。

# @file /etc/apache2/conf-enabled/git_http_backend.conf 
# 
# @brief 
# This conf to enable git accessing via HTTP over apaches. 
# 
# Tested on Ubuntu-14.04.5 
# 
# a2enmod dav dav_fs env alias proxy rewrite proxy_http 
# 

SetEnv GIT_PROJECT_ROOT   /var/www/html 
SetEnv GIT_HTTP_EXPORT_ALL  1 
SetEnv REMOTE_USER    $REDIRECT_REMOTE_USER 

ScriptAliasMatch \ 
    "(?x)^/(.*/(HEAD | \ 
     info/refs | \ 
     objects/(info/[^/]+ | \ 
      [0-9a-f]{2}/[0-9a-f]{38} | \ 
      pack/pack-[0-9a-f]{40}\.(pack|idx)) | \ 
      git-(upload|receive)-pack))$" \ 
    "/usr/lib/git-core/git-http-backend/$1" 

<Directory "/usr/lib/git-core"> 
    Options +ExecCgi -MultiViews +SymLinksIfOwnerMatch 
    AllowOverride none 
    Order allow,deny 
    Allow from all 
    Require all granted 
</Directory> 


# disable anonymous accessing /repo/* 
<LocationMatch "^/repo/.*"> 
    AuthType Basic 
    AuthName "Git" 
    AuthUserFile /etc/apache2/users.htpasswd 
    Require valid-user 
    Order allow,deny 
</LocationMatch> 


## foobar.git 
<Location /repo/foobar.git> 
    Options +ExecCGI 
    AuthType Basic 
    DAV on 
    AuthName "Git" 
    AuthUserFile /etc/apache2/users.htpasswd 
    Require valid-user 

    Order allow,deny 
    Allow from all 
</Location> 

###END###