簡體   English   中英

nginx 和 git-http-backend 403 推送

[英]nginx and git-http-backend 403 on push

我正在嘗試設置一個 git 服務器,前端使用stagitgit-http-backend使用git-http-backend並在所有內容之間使用nginx 我在這個答案中找到了一個在我的服務器上工作的配置(通過工作,我的意思是 nginx 將通過網絡瀏覽器為任何連接提供 html,但是如果我使用git clone https://git.website.com/test.git

我遇到的問題是,當我以https://git.website.com/test.git的來源推送此存儲庫(無論是來自服務器本身還是來自我的本地計算機)時,我收到 403錯誤,我不知道為什么。 有任何想法嗎?

server {
    listen 80;
    listen [::]:80;

    listen 443 ssl;
    listen [::]:443 ssl;

    ssl_certificate /etc/ssl/ssl-bundle.crt;
    ssl_certificate_key /etc/ssl/private/ssl-private.key;

    root /srv/git;

    index index.html index.htm index.nginx-debian.html;

    access_log /var/log/nginx/git.access.log;
    error_log /var/log/nginx/git.error.log;
    gzip off;

    location / {
        try_files $uri $uri/ =404;
    }

    # static repo files for cloning over https
    location ~ ^.*/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ {
        root /srv/git;
    }

    # requests that need to go to git-http-backend
    location ~ ^.*/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ {
        root /srv/git;

        fastcgi_pass  unix:/var/run/fcgiwrap.socket;
        fastcgi_param SCRIPT_FILENAME   /usr/lib/git-core/git-http-backend;
        fastcgi_param PATH_INFO         $uri;
        fastcgi_param GIT_PROJECT_ROOT  $document_root;
        fastcgi_param GIT_HTTP_EXPORT_ALL "";
        fastcgi_param REMOTE_USER $remote_user;
        include fastcgi_params;
    }   
}

大約兩個小時前,我才開始嘗試使用git-http-backend和多個配置。 讓 http 正常為網頁提供服務似乎非常困難,但允許 git 克隆/推送。 使用此處找到的配置導致空的 200 OK 響應...

經過多次反復試驗,我從這個答案中獲取了配置並對其進行了修改,以提供以下位置規則:

location / {
    if ($arg_service = git-receive-pack) {
        rewrite (/.*) /git_write/$1 last;
    }

    if ($uri ~ ^/.*/git-receive-pack$) {
        rewrite (/.*) /git_write/$1 last;
    }

    if ($arg_service = git-upload-pack) {
        rewrite (/.*) /git_read/$1 last;
    }

    if ($uri ~ ^/.*/git-upload-pack$) {
        rewrite (/.*) /git_read/$1 last;
    }
}

# pass PHP scripts to FastCGI server
location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.3-fpm.sock;
}

location ~ /git_read/(.*) {
    include git-http-backend.conf;
}

# require auth to upload
location ~ /git_write/(.*) {
    auth_basic "Pushing to Git repositories is restricted";
    auth_basic_user_file /etc/nginx/htpasswd;
    include git-http-backend.conf;
}

其中/etc/nginx/git-http-backend.conf讀取:

fastcgi_pass unix:/var/run/fcgiwrap.socket;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
fastcgi_param GIT_HTTP_EXPORT_ALL "";
fastcgi_param GIT_PROJECT_ROOT /srv/git;
fastcgi_param PATH_INFO $1;
fastcgi_param REMOTE_USER $remote_user;

問題解決了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM