抄来的 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;
}
1
feedcode 4 天前
(?x) 这个表示 Free-Spacing , 后面的空格和换行会 ignore
https://www.regular-expressions.info/freespacing.html |
3
feedcode 3 天前
你如果认为这里应该是或的关系,那改成|就行了
|