在运行Nginx的Arch Linux服务器上,我正确设置了cgit。我想用一个基本的认证密码来保护cgit,除了一个目录/pub/。正如在the documentation上看到的那样,我考虑在server上下文上进行身份验证,并在/pub/目录的location上下文中获得一个异常。我尝试了this link以获得正确的路径。
这里是对应块的nginx的配置文件。
server {
listen 80;
server_name git.nicosphere.net;
index cgit.cgi;
gzip off;
auth_basic "Restricted";
auth_basic_user_file /srv/gitosis/.htpasswd;
location / {
root /usr/share/webapps/cgit/;
}
location ^~ /pub/ {
auth_basic off;
}
if (!-f $request_filename) {
rewrite ^/([^?/]+/[^?]*)?(?:\?(.*))?$ /cgit.cgi?url=$1&$2 last;
}
location ~ \.cgi$ {
gzip off;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9001;
fastcgi_index cgit.cgi;
fastcgi_param SCRIPT_FILENAME /usr/share/webapps/cgit/cgit.cgi;
fastcgi_param DOCUMENT_ROOT /usr/share/webapps/cgit/;
}
}这会要求我对任何url进行身份验证。对于一些更简单的测试,我尝试离开根目录而不进行身份验证,只使用/pub/进行身份验证。在这种情况下,它根本不要求输入密码。到目前为止,我要么保护一切,要么什么都不保护。
谢谢你的帮助,并为我的近似英语道歉。
发布于 2012-05-08 21:10:50
我认为你想要这样的东西:
server {
listen 80;
server_name git.nicosphere.net;
index cgit.cgi;
gzip off;
root /usr/share/webapps/cgit;
# $document_root is now set properly, and you don't need to override it
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/cgit.cgi;
location / {
try_files $uri @cgit;
}
# Require auth for requests sent to cgit that originated in location /
location @cgit {
auth_basic "Restricted";
auth_basic_user_file /srv/gitosis/.htpasswd;
gzip off;
# rewrites in nginx don't match the query string
rewrite ^/([^/]+/.*)?$ /cgit.cgi?url=$1 break;
fastcgi_pass 127.0.0.1:9001;
}
location ^~ /pub/ {
gzip off;
rewrite ^/([^/]+/.*)?$ /cgit.cgi?url=$1 break;
fastcgi_pass 127.0.0.1:9001;
}
}https://stackoverflow.com/questions/10486340
复制相似问题