git - 如何使用用户/密码通过 NGINX 通过 HTTP 服务 GIT?

标签 git nginx

尽管我找到了所有关于如何配置 git/nginx 以获取我的存储库的链接,但我无法使它们工作。

我遵循了本教程,Git repository over HTTP WebDAV with nginx ,但用户/密码限制不起作用。任何人都可以克隆存储库。

我来自使用 SVN + Apache + DAV_SVN 的配置,带有一个密码文件(使用 htpasswd 创建)和一个 authz.conf 文件。我想做同样的事情,使用 git+nginx。这怎么可能?

感谢您的帮助!

最佳答案

看看下面的文章,http://www.toofishes.net/blog/git-smart-http-transport-nginx/

它提供了一个示例 nginx 配置:

http {
    ...
    server {
        listen       80;
        server_name  git.mydomain.com;

        location ~ /git(/.*) {
            # fcgiwrap is set up to listen on this host:port
            fastcgi_pass  localhost:9001;
            include       fastcgi_params;
            fastcgi_param SCRIPT_FILENAME     /usr/lib/git-core/git-http-backend;
            # export all repositories under GIT_PROJECT_ROOT
            fastcgi_param GIT_HTTP_EXPORT_ALL "";
            fastcgi_param GIT_PROJECT_ROOT    /srv/git;
            fastcgi_param PATH_INFO           $1;
        }
    }
}

这样做是将位于 url 中/git 之后的存储库传递给 /usr/lib/git-core/git-http-backend。例如,http://git.mydomain.com/git/someapp 将指向 someapp 存储库。此 repo 将位于 /srv/git/someapp 中,如 GIT_PROJECT_ROOTfastcgi_param 中所定义,并且可以更改以适合您的服务器。

这个很有用,可以申请HttpAuthBasicModule到 nginx 到密码保护你的 repo 通过 HTTP 访问。

编辑: 如果您缺少 git-http-backend,您可以在 Ubuntu/Debian 或基于 RPM 的平台查看 How can git be installed on CENTOS 5.5?

关于git - 如何使用用户/密码通过 NGINX 通过 HTTP 服务 GIT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6414227/

相关文章:

git - 如何在 git merge 上创建一条大消息?

nginx - 在 nginx 重写中发送额外的 header

nginx - 使用 Docker 和 Nginx proxy_pass 时重启容器

tomcat - xwiki 错误 : Duplicate query mapping getSpaceDocsName

git - 如何使用git将两个目录 merge 到同一个分支中

git - .gitconfig 的 [github] 部分如何工作?

android - 用于调试 Android 的 repo 'bisect'?

java - 如何使用 JitPack 从 GitHub 获取最新版本?

node.js - 如何使用Nginx通过express router加载页面

php - 使用 nginx 和 php7 无法加载任何 PHP 文件或在日志中看到任何错误