【问题标题】:Trying to setup smart http git server with nginx: "The requested URL returned error: 502"尝试使用 nginx 设置智能 http git 服务器:“请求的 URL 返回错误:502”
【发布时间】:2017-05-23 17:34:01
【问题描述】:

我正在尝试通过将smart http 与 nginx 一起使用来为 git 存储库设置服务器。 我关注了https://stackoverflow.com/a/17553364上的答案。

虽然当我执行git clone http://mydomian.de/git/test 时,它会返回:

Cloning into 'xmlTest' ...
fatal: unable to access 'http://mydomain.de/git/test/': The requested URL returned error: 502

并且 nginx 错误日志打印两次:

2016/11/16 07:29:11 [error] 19219#0: *11 connect() failed (111: Connection refused) while connecting to upstream, client: myip, server: mydomain.de, request: "GET /git/test/info/refs?service=git-upload-pack HTTP/1.1", upstream: "fastcgi://127.0.0.1:9001", host: "mydomain.de"

我在 /srv/git/ 中放置了一个名为 test 的裸 git repo。

我安装了 git-core。

我认为 fcgiwrap 正在运行,因为 sudo service fcgiwrap status 返回:

[ ok ] Checking status of FastCGI wrapper: fcgiwrap running.

这是我用于 nginx 的配置的相关部分:

server {
    root /usr/share/nginx/mydomain/www;
        index index.html index.htm;

        # Make site accessible from mydomain.de
        server_name mydomain.de;

        access_log /var/log/nginx/mydomain.access.log;
        error_log /var/log/nginx/mydomain.error.log;

        proxy_set_header X-Forwarded-For $remote_addr;  

        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;

        location /doc/ {
                alias /usr/share/doc/;
                autoindex on;
                allow 127.0.0.1;
                allow ::1;
                deny all;
        }
}

提前感谢您的帮助;)

【问题讨论】:

    标签: git nginx git-http-backend


    【解决方案1】:

    尝试:

    location ~ (/.*) {
      client_max_body_size 0; # Git pushes can be massive, just to make sure nginx doesn't suddenly cut the connection add this.
      auth_basic "Git Login"; # Whatever text will do.
      auth_basic_user_file "/var/www/git/htpasswd";
      include /etc/nginx/fastcgi_params; # Include the default fastcgi configs
      fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; # Tells 
      fastcgi to pass the request to the git http backend executable
      fastcgi_param GIT_HTTP_EXPORT_ALL "";
      fastcgi_param GIT_PROJECT_ROOT /var/www/git/html; # /var/www/git is the location of all of your git repositories.
      fastcgi_param REMOTE_USER $remote_user;
      fastcgi_param PATH_INFO $1; # Takes the capture group from our location directive and gives git that.
      fastcgi_pass  unix:/var/run/fcgiwrap.socket; # Pass the request to fastcgi
    }
    

    重要! fastcgi_pass 必须是最后一个。

    【讨论】:

      【解决方案2】:

      根据enter link description here,你可能需要检查nginx是否可以写入git repos目录。

      【讨论】:

        猜你喜欢
        • 2020-10-09
        • 2018-11-25
        • 2018-02-04
        • 2014-06-28
        • 2015-07-16
        • 2019-05-29
        • 1970-01-01
        • 1970-01-01
        • 2017-11-30
        相关资源
        最近更新 更多