抄来的 nginx 配置,第 1 个 location 的正则表达式不太确定是否正确。按照 AI 的解答,用于匹配下面这几种路径。实测下来,http git clone 也是失败的,未匹配第 1 个 location 。有几个疑点:
location ~ "(?x)^/git(?<path>/.*/(?:HEAD '
info/refs '
objects/(?:info/[^/]+ '
[0-9a-f]{2}/[0-9a-f]{38} '
pack/pack-[0-9a-f]{40}\.(?:pack '
idx)) '
git-upload-pack))$" {
error_page 491 = @auth;
if ($query_string = service=git-receive-pack) {
return 491;
}
client_max_body_size 0;
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
include fastcgi_params;
fastcgi_param GIT_HTTP_EXPORT_ALL "";
fastcgi_param GIT_PROJECT_ROOT /srv/git;
fastcgi_param PATH_INFO $path;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}
location ~ "^/git(?<path>/.*/git-receive-pack)$" {
error_page 491 = @auth;
return 491;
}
location @auth {
auth_basic "Git write access";
auth_basic_user_file /srv/git/.htpasswd;
client_max_body_size 0;
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
include fastcgi_params;
fastcgi_param GIT_HTTP_EXPORT_ALL "";
fastcgi_param GIT_PROJECT_ROOT /srv/git;
fastcgi_param PATH_INFO $path;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}
location ~ ^/git(?<path>/.*)$ {
alias /usr/share/cgit;
try_files $1 @cgit;
}
location @cgit {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/lib/cgit/cgit.cgi;
fastcgi_param PATH_INFO $path;
fastcgi_param QUERY_STRING $args;
fastcgi_param HTTP_HOST $server_name;
fastcgi_param CGIT_CONFIG /srv/git/.cgitrc;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.