2014-07-22 36 views
0

我通過Nginx + Unicorn使用Gitlab 7。一旦啓用HTTP基本身份驗證,git命令(如「git push」或「git pull」)停止工作。沒有HTTP基本認證所有工作正常。我如何解決它?我需要啓用HTTP基本身份驗證,而不會對開發人員造成任何損害。 我的nginx的conf文件爲gitlab:通過HTTP的Git命令基本身份驗證

upstream gitlab { 
server unix:/home/git/gitlab/tmp/sockets/gitlab.socket; 
} 
server { 
    listen *:80 default_server; 
    server_name gitlab.delfit.com; 
    server_tokens off; 
    root /home/git/gitlab/public; 

    client_max_body_size 300m; 

    # individual nginx logs for this gitlab vhost 
    access_log /var/log/nginx/gitlab_access.log; 
    error_log /var/log/nginx/gitlab_error.log; 

    location/{ 
    # serve static files from defined root folder;. 
    # @gitlab is a named location for the upstream fallback, see below 
    try_files $uri $uri/index.html $uri.html @gitlab; 
    } 

    # if a file, which is not found in the root folder is requested, 
    # then the proxy pass the request to the upsteam (gitlab unicorn) 
    location @gitlab { 
    proxy_read_timeout 300; 
    proxy_connect_timeout 300; 
    proxy_redirect  off; 

    proxy_set_header X-Forwarded-Proto $scheme; 
    proxy_set_header Host    $http_host; 
    proxy_set_header X-Real-IP   $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 

# auth_basic "Restricted"; 
# auth_basic_user_file /home/git/gitlab/.htpasswd;  

    proxy_pass http://gitlab; 
    } 

    error_page 502 /502.html; 
} 

啓用基本身份驗證後的錯誤是:

[email protected]:~/git/myproject$ git push 
fatal: Authentication failed for 'http://gitlab.myorg.com/user/repo.git' 

提前感謝!

+0

你使用的是什麼版本的'git'?用'git --version'獲取它。當使用git將/ push到gitlab時,我面臨一些問題<1.7.10 – PierreF

回答

0

所以你已經設法添加兩層認證。一個在nginx層,然後Gitlab在你推/拉倉庫時擁有它自己的。

下面是您創建的流程。當有人推送代碼時,他們試圖對nginx認證進行認證,而不是針對Gitlab。一旦用戶通過nginx認證,他們將不得不對Gitlab進行認證。然後,您將通過gitlab進行身份驗證,但這不會讓您對nginx進行身份驗證,因爲HTTP只能保存一組憑據。

我個人只是讓Gitlab的內置認證做它的工作。但是,如果你確實必須在nginx上進行身份驗證,我看到兩個選項。從Gitlab切換到SSH,並且不要使用HTTP來推送和拉取存儲庫。或者,在nginx中添加條件語句,以便在URL匹配{repo}.git或類似格式時不提示進行身份驗證。但要警告,if is evil in nginx

+0

感謝您的回答。我真的需要2層保護我的gitlab網站。但我已經在使用SSH類型的拉和推。這就是爲什麼我完全沒有想法,爲什麼請求通過HTTP服務器。 – fesia

+0

而不是使用'if'語句,您是否建議使用兩個位置,一個用於匿名讀取,另一個用於驗證寫入? –