Nginx Git服务器返回错误500 [英] Nginx git server returns error 500

查看:139
本文介绍了Nginx Git服务器返回错误500的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为裸露的git存储库设置一个nginx远程服务器(带有ssl),但是从git bash(Windows 7计算机)尝试git clone https://my.domain.com/repo.git时却得到了error 500.

I'm trying to set up an nginx remote server (with ssl) for a bare git repository, but getting error 500 when trying git clone https://my.domain.com/repo.git from git bash (windows 7 machine).

我当前的配置如下.

Nginx服务器配置:

Nginx server config:

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的帮助:

I've consulted this source for help with setting up the 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时收到的确切错误:

The exact error I receive upon running git clone http://my.domain.com/repo.git:

克隆到'repo'...致命:无法访问' http://my.domain.com/repo.git ':所请求的URL返回错误: 500

Cloning into 'repo'... fatal: unable to access 'http://my.domain.com/repo.git': The requested URL returned error: 500

这是URL访问日志的摘录:

This is the extract from the URL's access log:

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

URL的错误日志为空.

The URL's error log is empty.

我已经遍历了每个步骤,并详细介绍了此帖子中描述的其他人: https://superuser.com/questions/719949/centos-5-nginx-git-http-backend 但到目前为止我还没有成功.

I've already gone through every step and detail another person described in this post: https://superuser.com/questions/719949/centos-5-nginx-git-http-backend but I had no success so far.

更新#1

我尝试注释掉nginx服务器配置的位置设置中的fastgci参数,并指定位置网址本身,从而导致

I've tried commenting out the fastgci parameters in the nginx server config's location setting and specifying the location url itself, resulting in this

location /repo.git {
  client_max_body_size 0;

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

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

The result is now that when I try git clone http://my.domain.com/repo.git I get the following output in git bash:

克隆到"repo" ...
' http://my.domain.com '的用户名:git
" http://git@my.domain.com 的密码:...
致命: http://my.domain.com/repo.git/info/refs 无效:这是git存储库吗?

Cloning into 'repo'...
Username for 'http://my.domain.com': git
Password for 'http://git@my.domain.com': ...
fatal: http://my.domain.com/repo.git/info/refs not valid: is this a git repository?

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

But I can reach both http://my.domain.com and http://my.domain.com/repo.git in the browser

更新#2

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

I had a loot at this website: http://weininger.net/configuration-of-nginx-for-gitweb-and-git-http-backend.html, which helped me solve my issue, somehow.

现在我最终的Nginx服务器配置如下:

My final Nginx server configuration now looks like this:

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会给我以下错误

This allowed me to properly do a git clone and git pull without any errors, but git push would give me the following error

计数对象:4个,已完成.
最多可使用4个线程进行Delta压缩.
压缩对象:已完成100%(2/2).
写入对象:100%(3/3),312个字节|完成速度:0字节/秒.
总计3(增量0),已重用0(增量0)
错误:解压缩失败:解压缩对象异常退出
http://my.domain.com/repo.git
! [远程拒绝]主机->主机(不适用(拆包错误))
错误:无法将某些引用推送到' http://my.domain.com/repo '

Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 312 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
error: unpack failed: unpack-objects abnormal exit
To http://my.domain.com/repo.git
! [remote rejected] master -> master (n/a (unpacker error))
error: failed to push some refs to 'http://my.domain.com/repo'

更新#3

似乎unpack failed错误是由于权限问题引起的.即使我做了chown -R git:git repo.git,我也无法推送到存储库.但是做chown -R git:nginx repo.git解决了它.考虑到这是fastcgi脚本进行编写的(我想是吗?),我又部分理解了该脚本,而脚本又是Nginx产生的.

Seems the unpack failed error was due to a permission problem. Even though I did chown -R git:git repo.git I could not push to the repository. But doing chown -R git:nginx repo.git solved it. Which I partially understand, considering that it's the fastcgi script doing the writing (I suppose?), which in turn is spawned by Nginx.

如果有人可以的话,为了更好地学习和理解事物,对这些设置为何以它们的工作方式进行一些澄清或更深入的解释将是很好的.

Some clarification or deeper explanation of why these settings work the way they do would be great though, in order to learn and understand things better, if anybody can.

推荐答案

通过大量(重新)搜索和审判/错误解决了我的问题.我所采取的步骤会在问题的更新中详细记录下来.

Solved my issues through a lot of (re)search and trial/error. The steps I've taken are written down in detail in the question's updates.

这篇关于Nginx Git服务器返回错误500的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆