我使用 nginx 和 git-web,效果很好。我使用 www.mydomain.org 访问我的网站以启动 gitweb。这是我的配置文件:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name www.mydomain.org;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name www.mydomain.org;
ssl on;
ssl_certificate /etc/nginx/ssl/mydomain_org/www_mydomain_org.crt;
ssl_certificate_key /etc/nginx/ssl/mydomain_org/www_mydomain_org.key;
ssl_session_timeout 5m;
#enables all versions of TLS, but not SSLv2 or 3 which are weak and now deprecated.
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#Disables all weak ciphers
ssl_ciphers "Cut it out cause it was very long in question";
ssl_prefer_server_ciphers on;
root /var/www/html;
auth_basic "Restricted";
auth_basic_user_file git_access_list;
location /html {
root /var/www;
index index.html;
access_log off;
expires max;
}
# static repo files for cloning over https
location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ {
root /media/drive1/gitrepo/;
}
# requests that need to go to git-http-backend
location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ {
root /media/drive1/gitrepo;
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 /media/drive1/gitrepo;
fastcgi_param GIT_HTTP_EXPORT_ALL "";
fastcgi_param REMOTE_USER $remote_user;
include fastcgi_params;
}
# send anything else to gitweb if it's not a real file
try_files $uri @gitweb;
location @gitweb {
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_param SCRIPT_FILENAME /usr/share/gitweb/gitweb.cgi;
fastcgi_param PATH_INFO $uri;
fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
include fastcgi_params;
}
location /index.cgi {
root /usr/share/gitweb;
include fastcgi_params;
gzip off;
fastcgi_param SCRIPT_NAME $uri;
fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}
location / {
root /usr/share/gitweb/;
index index.cgi;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
我想做的是有一个 git 子文件夹而不是 ex: www.mydomain.org/git 来拉起 gitweb 主页。我不太确定如何更改它并且有点卡住了。关于如何做到这一点的任何建议或提示?
谢谢
更新
我通过修改以下内容弄清楚了:
location /index.cgi {
root /usr/share/gitweb;
include fastcgi_params;
gzip off;
fastcgi_param SCRIPT_NAME $uri;
fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}
location / {
root /usr/share/gitweb/;
index index.cgi;
}
至
location /git/static/ {
alias /usr/share/gitweb/static/;
}
location /git/ {
auth_basic "Restricted";
auth_basic_user_file git_access_list;
alias /usr/share/gitweb/;
fastcgi_param SCRIPT_FILENAME /usr/share/gitweb/index.cgi;
include fastcgi_params;
gzip off;
fastcgi_param GITWEB_CONFIG /etc/gitweb.conf;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}