首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nginx git服务器返回错误500。

Nginx git服务器返回错误500。
EN

Stack Overflow用户
提问于 2015-05-06 15:33:57
回答 1查看 1.7K关注 0票数 1

我正在尝试为一个裸的git存储库设置一个nginx远程服务器(使用ssl),但是在从git (windows 7机器)尝试error 500时获得git clone https://my.domain.com/repo.git

我当前的配置如下所示。

Nginx服务器配置:

代码语言:javascript
复制
server {
  listen: 80;
  server_name my.domain.com;
  # Redirect all non-HTTPS traffic to the HTTPS version
  return 301 https://my.domain.com;
}

server {
  listen 443 ssl;
  server_name my.domain.com;
  root /var/www/git;
  index index.html;

  ssl_certificate /etc/nginx/ssl/nxing.crt;
  ssl_certificate_key /etc/nginx/ssl/nginx.key;

  access_log /var/www/git/git.access.log;
  error_log /var/www/git/git.error.log;

  auth_basic "Git authentication required";
  auth_basic_user_file /etc/nginx/users_git;

  location / {
    client_max_body_size 0;

    include /etc/nginx/fastcgi_params;
    fastcgi_param SCRIPT_FILENAME /usr/libexec/git-core/git-http-backend;
    fastcgi_param GIT_HTTP_EXPORT_ALL "";
    fastcgi_param GIT_PROJECT_ROOT /repo.git;
    fastcgi_param PATH_INFO $1;
    fastcgi_param REMOTE_USER $remote_user;

    fastcgi_pass unix:/var/run/fcgiwrap.socket;
  }
}

我查阅了这个源代码,以获得关于设置fcgiwrap:http://knowledgebase.cc/en/software-en/linux-en/how-to-install-fcgiwrap-to-serving-cgiperl-scripts-in-nginx/的帮助

运行git clone http://my.domain.com/repo.git时所收到的确切错误

克隆成‘回购’..。致命:无法访问“http://my.domain.com/repo.git”:请求的URL返回错误: 500

这是URL访问日志的摘录:

1xx.xxx.xxx.xx -06/5/2015:17:29:02 +0200 "GET / HTTP/1.1“500 5- "git/1.9.5.msysgit.1”

URL的错误日志为空。

我已经经历了这篇文章中描述的另一个人的每一个步骤和细节:https://superuser.com/questions/719949/centos-5-nginx-git-http-backend,但是到目前为止我还没有成功。

更新#1

我尝试注释nginx服务器配置的位置设置中的快速this参数,并指定位置url本身,结果如下

代码语言:javascript
复制
location /repo.git {
  client_max_body_size 0;

  [...] commented fastcgi params [...]
}

现在的结果是,当我尝试使用git clone http://my.domain.com/repo.git时,我在git中获得了以下输出:

克隆成‘回购’..。 “http://my.domain.com”的用户名: git http://git@my.domain.com的密码:. 致命:http://my.domain.com/repo.git/info/refs无效:这是一个git存储库吗?

但是我可以在浏览器中访问http://my.domain.comhttp://my.domain.com/repo.git

更新#2

我在这个网站上得到了一个战利品:http://weininger.net/configuration-of-nginx-for-gitweb-and-git-http-backend.html,它以某种方式帮助我解决了我的问题。

我最后的Nginx服务器配置现在如下所示:

代码语言:javascript
复制
server {
  listen 80;
  server_name my.domain.com;
  # Redirect all non-HTTPS traffic to the HTTPS version
  rewrite ^ https://$server_name$request_uri? permanent;
}

server {
  listen 443 ssl;
  server_name my.domain.com;
  root /var/www/git;
  index index.html;

  ssl_certificate /etc/nginx/ssl/nginx.crt;
  ssl_certificate_key /etc/nginx/ssl/nginx.key;

  access_log /var/www/git/git.access.log;
  error_log /var/www/git/git.error.log;

  auth_basic "Git authentication required";
  auth_basic_user_file /etc/nginx/users_git;

  location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ {

    include /etc/nginx/fastcgi_params;
    fastcgi_param SCRIPT_FILENAME /usr/libexec/git-core/git-http-backend;
    fastcgi_param GIT_HTTP_EXPORT_ALL "";
    fastcgi_param GIT_PROJECT_ROOT /var/www/git;
    fastcgi_param PATH_INFO $uri;
    fastcgi_param REMOTE_USER $remote_user;

    fastcgi_pass unix:/var/run/fcgiwrap.socket;
  }
}

这使我能够正确地执行git clonegit pull,而不会出现任何错误,但是git push会给出以下错误

计数对象: 4,完成。 三角洲压缩使用最多4个线程。 压缩对象: 100% (2/2),完成。 写入对象: 100% (3/3),312字节,0字节/s,已完成。 共计3 (delta 0),重用0 (delta 0) 错误:解压缩失败:解压对象异常退出 转到http://my.domain.com/repo.git 好了!远程拒绝主->母版(n/a (解包错误)) 错误:未能将一些参考文献推送到“http://my.domain.com/repo

更新#3

似乎unpack failed错误是由于权限问题造成的。即使我做了chown -R git:git repo.git,我也不能推送到存储库。但是做chown -R git:nginx repo.git解决了这个问题。考虑到这是由fastcgi脚本编写的(我想?),这一点我部分理解,而这又是由Nginx生成的。

一些澄清或更深入的解释,为什么这些设置的工作方式,但将是伟大的,但为了更好地学习和理解,如果任何人可以的话。

EN

回答 1

Stack Overflow用户

发布于 2015-05-07 10:19:37

通过大量的搜索和尝试/错误解决了我的问题。我所采取的步骤被详细记录在问题的更新中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30081316

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档