用 nginx 直接提供 Git HTTP 访问
-
安装
nginxsudo apt install nginx -
修改
/etc/nginx/sites-available/default添加:
server { listen 80; server_name your-ip;
location /git/ {
root /home/six-my/mirrors;
autoindex on;
}
}
-
重启
nginxsudo systemctl restart nginx
然后你可以直接用 http://your-ip/git/github.com/OnePlusOSS/android_kernel_common_oneplus_sm8550.git 访问仓库。
通过 HTTP 访问(适合局域网)
如果你希望在局域网中让其他设备访问 /home/six-my/mirrors/,可以用 git-http-backend 让它支持 HTTP 访问。
1. 安装 Apache(Debian/Ubuntu)
bash
复制编辑
sudo apt update sudo apt install apache2 git sudo a2enmod cgi alias sudo systemctl restart apache2
2. 配置 Apache
创建 /etc/apache2/sites-available/git.conf:
swift
复制编辑
<VirtualHost *:80> ServerName your-ip DocumentRoot /home/six-my/mirrors ScriptAlias /git/ /usr/lib/git-core/git-http-backend/ SetEnv GIT_PROJECT_ROOT /home/six-my/mirrors SetEnv GIT_HTTP_EXPORT_ALL <Directory "/home/six-my/mirrors"> Require all granted </Directory> </VirtualHost>
3. 启用配置
bash
复制编辑
sudo a2ensite git sudo systemctl restart apache2
4. 远程访问
在局域网的另一台机器上:
bash
复制编辑
git clone http://your-ip/git/repo.git