フロントエンドに stagit 、バックエンドに git-http-backend を使用し、すべての間で nginx を使用して git サーバーをセットアップしようとしています。この回答でサーバー上で動作する構成を見つけました(動作するとは、nginxがWebブラウザを介してあらゆる接続に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;
}
}
私は約 2 時間前に複数の構成で git-http-backend を使用しようと試み始めたばかりです。 http を取得して Web ページを正常に提供することは非常に難しいようですが、すべての Web ページを提供することもできます。git でクローン/プッシュを実行します。ここにある構成を使用すると、空の 200 OK 応答が返されました...
------------------------
多くの試行錯誤の後、この回答から構成を取得し、次の場所ルールを与えるように変更しました。
location / {
if ($arg_service = git-receive-pack) {
rewrite (/.*) /git_write/ last;
}
if ($uri ~ ^/.*/git-receive-pack$) {
rewrite (/.*) /git_write/ last;
}
if ($arg_service = git-upload-pack) {
rewrite (/.*) /git_read/ last;
}
if ($uri ~ ^/.*/git-upload-pack$) {
rewrite (/.*) /git_read/ 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 ;
fastcgi_param REMOTE_USER $remote_user;
問題は解決しました。
共有
この回答を改善します
フォローする
2020 年 9 月 5 日 12:31 に回答
ユーザー13283549
ユーザー13283549