我有這個
location ~ ^.*user/repo\.git\/(HEAD|info/refs|objects/info/.*|git-upload-pack)${
//send to fastcgi_param SCRIPT_FILENAME /usr/bin/gitolite-shell;
}
這適用於克隆。我已經修改了 Gitolite,這樣我就可以在沒有金鑰或 http 使用者/密碼的情況下建立公共儲存庫。
現在,當我想推送訊息/參考與此路線匹配時,我無法移動到負責推送的下一個位置。
location ~ ^.*user/repo\.git\/(HEAD|info/refs|objects/info/.*|git-receive-pack)${
//some custom auth and so on
}
順便說一句,這正在 apache 中用於推送公共存儲庫:
<LocationMatch "^/username/repo/git-receive-pack$">
</LocationMatch>
底線是:
^.*user/repo\.git\/(HEAD|info/refs|objects/info/.*|git-upload-pack)$
^.*user/repo\.git\/(HEAD|info/refs|objects/info/.*|git-receive-pack)$
都是問題,因為第一個總是會追上第二個。
我嘗試做一些
if ($args = "service=git-receive-pack"){
//do redirect to user/repo.git/git-receive-pack but that will not work since
//info/refs?service=git-receive-pack must be called first.
}
我需要正規表示式方面的幫助,並且不要忘記您無法匹配 Nginx 位置中的位置查詢字串。例如
user/repo.git/info/refs?service=git-receive-pack
user/repo.git/git-receive-pack
可以用簡單的`^來配對。使用者/repo.git/。(git-receive-pack)$.這將不起作用,因為 Nginx 中的第一種情況不匹配,因為位置是 user/repo.git/info/refs。
答案1
24小時後我解決了這個問題:(
這是對我有用的解決方案。
location = /username/repo.git/info/refs {
if ($args ~ service=git-upload-pack) {
rewrite ^ /username/repo.git/git-upload-pack;
}
if ($args ~ service=git-receive-pack){
rewrite ^ /username/repo.git/git-receive-pack;
}
}
location ~ /username/repo.git/git-upload-pack {
gzip off;
if ( $request_method ~ POST ){
set $uri1 $uri;
}
if ( $request_method ~ GET ){
set $uri1 /username/repo.git/info/refs;
}
fastcgi_param PATH_INFO $uri1;
fastcgi_param REMOTE_USER daemon;
fastcgi_param GIT_PROJECT_ROOT /var/lib/gitolite/repositories;
fastcgi_param GITOLITE_HTTP_HOME /var/lib/gitolite;
fastcgi_param SCRIPT_FILENAME /usr/bin/gitolite-shell;
fastcgi_param QUERY_STRING $query_string;
fastcgi_pass 127.0.0.1:1234;
include fastcgi_params;
}
location = /username/repo.git/git-receive-pack{
gzip off;
if ( $request_method ~ POST ){
set $uri1 $uri;
}
if ( $request_method ~ GET ){
set $uri1 /username/repo.git/info/refs;
}
satisfy any;
auth_basic "Restricted Access for repository_path";
auth_basic_user_file "/usr/local/nginx/htpasswd";
auth_request /auth;
fastcgi_param PATH_INFO $uri1;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_param GIT_PROJECT_ROOT /var/lib/gitolite/repositories;
fastcgi_param GITOLITE_HTTP_HOME /var/lib/gitolite;
fastcgi_param SCRIPT_FILENAME /usr/bin/gitolite-shell;
fastcgi_param QUERY_STRING $query_string;
fastcgi_pass 127.0.0.1:1234;
include fastcgi_params;
}
這個 nginx 很糟糕,因為我只需要 5 行程式碼就可以解決 apache 中公共儲存庫的拉/推問題。我希望花費的這些時間是值得的。