我在 domain.fr 上有一个 CentOS 5 服务器。我试图设置一个子域名,以便可以将其与 git 一起使用,“git.domain.fr”。
- 我的存储库位于
/home/git
(示例/home/git/repos.git
)。 - 我已经安装了
git-http-backend and nginx
。 - 我设置了这样的存储库:
cd /home/git/repos.git && git --bare init
。 - 我已将我的
git.conf
(包含在内nginx.conf
)设置如下。
然而,在我的客户端 shell 上,我得到了致命错误“未找到存储库”:
$ git clone http://git.domain.fr/repos.git
有人知道我该怎么办吗?这看起来很简单,我很沮丧,因为我确定这没什么……
server {
listen 80;
server_name git.domain.fr;
root /home/git;
location ~ /(/.*) {
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/bin/git-http-backend;
fastcgi_param GIT_HTTP_EXPORT_ALL true;
fastcgi_param GIT_PROJECT_ROOT /home/git;
fastcgi_param PATH_INFO $1;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}
}
编辑#1
我已将文件更新如下:
server {
listen 80;
server_name git.domain.fr;
root /home/git;
access_log /var/log/httpd/git.access.log;
error_log /var/log/httpd/git.error.log;
location / {
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/bin/git-http-backend;
fastcgi_param GIT_HTTP_EXPORT_ALL true;
fastcgi_param GIT_PROJECT_ROOT /home/git;
fastcgi_param PATH_INFO $uri;
fastcgi_pass unix:/usr/local/src/fcgiwrap/systemd/fcgiwrap.socket;
}
}
我还检查了插座位置并将其提供给了nginx:nginx
,但现在出现了“错误 500”。
$ git clone git.domain.fr/repos.git
Cloning into 'repos'...
fatal: unable to access 'git.domain.fr/repos.git/': The requested URL returned error: 500
fcgi wrap 正在运行:
$ netstat -anp | grep cgi
unix 2 [ ACC ] STREAM LISTENING 1510861 24878/fcgiwrap /usr/local/src/fcgiwrap/systemd/fcgiwrap.socket
它具有正确的权限:
$ ls -lia /usr/local/src/fcgiwrap/systemd/fcgiwrap.socket
3067341 srwxrwxrwx 1 nginx nginx 0 févr. 22 23:51 /usr/local/src/fcgiwrap/systemd/fcgiwrap.socket
git.error.log
为空,但git.access.log
包含:
1**.***.***.*** - - [23/Feb/2014:13:02:17 +0100] "GET /repos.git/info/refs?service=git-upload-pack HTTP/1.1" 500 5 "-" "git/1.8.4"
编辑#2
问题几乎解决了:我只是因为某些原因重新启动了服务器,然后就可以git pull
正常工作了。
现在,当我推送时出现 403 错误。
推 :
$ GIT_CURL_VERBOSE=1 git push origin master
* Adding handle: conn: 0x7fe329811800
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fe329811800) send_pipe: 1, recv_pipe: 0
* About to connect() to git.domain.fr port 80 (#0)
* Trying 108.162.199.22...
* Connected to git.domain.fr (108.162.199.22) port 80 (#0)
> GET /repos.git/info/refs?service=git-receive-pack HTTP/1.1
User-Agent: git/1.8.4
Host: git.domain.fr
Accept: */*
Accept-Encoding: gzip
Pragma: no-cache
< HTTP/1.1 403 Forbidden
* Server cloudflare-nginx is not blacklisted
< Server: cloudflare-nginx
< Date: Sun, 23 Feb 2014 18:20:59 GMT
< Content-Type: application/octet-stream
< Transfer-Encoding: chunked
< Connection: keep-alive
< Set-Cookie: __cfduid=dc7d61cac342494e2b1307f88f8bf440f1393179659791; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.domain.fr; HttpOnly
< Expires: Fri, 01 Jan 1980 00:00:00 GMT
< Pragma: no-cache
< Cache-Control: no-cache, max-age=0, must-revalidate
< Expires: Fri, 01 Jan 1980 00:00:00 GMT
< Pragma: no-cache
< Cache-Control: no-cache, max-age=0, must-revalidate
< CF-RAY: 1015eee9b29a091a-CDG
<
* Connection #0 to host git.domain.fr left intact
fatal: unable to access 'http://git.domain.fr/repos.git/': The requested URL returned error: 403
拉 :
$ GIT_CURL_VERBOSE=1 git pull origin master
* Adding handle: conn: 0x7fb11b811800
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fb11b811800) send_pipe: 1, recv_pipe: 0
* About to connect() to git.domain.fr port 80 (#0)
* Trying 108.162.198.22...
* Connected to git.domain.fr (108.162.198.22) port 80 (#0)
> GET /repos.git/info/refs?service=git-upload-pack HTTP/1.1
User-Agent: git/1.8.4
Host: git.domain.fr
Accept: */*
Accept-Encoding: gzip
Pragma: no-cache
< HTTP/1.1 200 OK
* Server cloudflare-nginx is not blacklisted
< Server: cloudflare-nginx
< Date: Sun, 23 Feb 2014 18:25:33 GMT
< Content-Type: application/x-git-upload-pack-advertisement
< Transfer-Encoding: chunked
< Connection: keep-alive
< Set-Cookie: __cfduid=d75ab90529a399f012383cdee482bc7ed1393179933224; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.domain.fr; HttpOnly
< Expires: Fri, 01 Jan 1980 00:00:00 GMT
< Pragma: no-cache
< Cache-Control: no-cache, max-age=0, must-revalidate
< CF-RAY: 1015f596a8700914-CDG
<
* Connection #0 to host git.domain.fr left intact
From http://git.domain.fr/repos
* branch master -> FETCH_HEAD
Already up-to-date.
日志(error.log为空):
$ tail -f /var/log/httpd/git.access.log
1**.***.***.*** - - [23/Feb/2014:19:20:59 +0100] "GET /repos.git/info/refs?service=git-receive-pack HTTP/1.1" 403 5 "-" "git/1.8.4"
1**.***.***.*** - - [23/Feb/2014:19:25:33 +0100] "GET /repos.git/info/refs?service=git-upload-pack HTTP/1.1" 200 294 "-" "git/1.8.4"
我检查了权利和所有者。我能做什么?有什么想法吗?
编辑#3
成功 !
如果在未进行身份验证的情况下使用 Git push,则会出现 403 错误。我只需设置 nginx,让它要求输入用户/密码:
server {
listen 80;
server_name git.domain.fr;
root /home/git;
access_log /var/log/httpd/git.access.log;
error_log /var/log/httpd/git.error.log;
auth_basic "Accès restreint";
auth_basic_user_file /home/domain.fr/git_access;
location / {
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/bin/git-http-backend;
fastcgi_param GIT_HTTP_EXPORT_ALL true;
fastcgi_param GIT_PROJECT_ROOT /home/git;
fastcgi_param PATH_INFO $uri;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_pass unix:/usr/local/src/fcgiwrap/systemd/fcgiwrap.socket;
}
}
您还应该检查您的存储库是否属于git:git
:
chmod -R g+ws repos.git
chgrp -R git repos.git
现在一切都好。
感谢您的帮助 !
答案1
您的位置匹配以两个斜杠开头的 URI,这在默认的 nginx 配置下是不可能的。此外,如果您想要代理所有请求,则无需使用正则表达式位置。这个应该适合您:
location / {
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/bin/git-http-backend;
fastcgi_param GIT_HTTP_EXPORT_ALL true;
fastcgi_param GIT_PROJECT_ROOT /home/git;
fastcgi_param PATH_INFO $uri;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}