Arn*_*aud 10 nginx git fcgi gitolite
我正在尝试设置一个可以通过 HTTP(S) 访问我的 git repo 的服务器。
我正在使用 gitolite 和 nginx(以及用于 Web 界面的 gitlab,但我怀疑它有什么区别)。
我搜索了整个下午,我想我被卡住了。
我想我已经明白 nginx 需要 fcgiwrap 才能与 gitolite 一起工作,所以我尝试了几种配置,但都没有工作。
我的存储库位于 /home/git/repositories。
这是我尝试过的三种 nginx 配置。
1:
location ~ /git(/.*) {
gzip off;
root /usr/lib/git-core;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
include /etc/nginx/fcgiwrap.conf;
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
fastcgi_param DOCUMENT_ROOT /usr/lib/git-core/;
fastcgi_param SCRIPT_NAME git-http-backend;
fastcgi_param GIT_HTTP_EXPORT_ALL "";
fastcgi_param GIT_PROJECT_ROOT /home/git/repositories;
fastcgi_param PATH_INFO $1;
#fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
}
Run Code Online (Sandbox Code Playgroud)
结果:
> git clone http://myservername/projectname.git test/
Cloning into test...
fatal: http://myservername/projectname.git/info/refs not found: did you run git update-server-info on the server?
Run Code Online (Sandbox Code Playgroud)
和
> git clone http://myservername/git/projectname.git test/
Cloning into test...
error: The requested URL returned error: 502 while accessing http://myservername/git/projectname.git/info/refs
fatal: HTTP request failed
Run Code Online (Sandbox Code Playgroud)
2:
location ~ /git(/.*) {
fastcgi_pass localhost:9001;
include /etc/nginx/fcgiwrap.conf;
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
fastcgi_param GIT_HTTP_EXPORT_ALL "";
fastcgi_param GIT_PROJECT_ROOT /home/git/repositories;
fastcgi_param PATH_INFO $1;
}
Run Code Online (Sandbox Code Playgroud)
结果:
> git clone http://myservername/projectname.git test/
Cloning into test...
fatal: http://myservername/projectname.git/info/refs not found: did you run git update-server-info on the server?
Run Code Online (Sandbox Code Playgroud)
和
> git clone http://myservername/git/projectname.git test/
Cloning into test...
error: The requested URL returned error: 502 while accessing http://myservername/git/projectname.git/info/refs
fatal: HTTP request failed
Run Code Online (Sandbox Code Playgroud)
3:
location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ {
root /home/git/repositories/;
}
location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ {
root /home/git/repositories;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
fastcgi_param PATH_INFO $uri;
fastcgi_param GIT_PROJECT_ROOT /home/git/repositories;
include /etc/nginx/fcgiwrap.conf;
}
Run Code Online (Sandbox Code Playgroud)
结果:
> git clone http://myservername/projectname.git test/
Cloning into test...
error: The requested URL returned error: 502 while accessing http://myservername/projectname.git/info/refs
fatal: HTTP request failed
Run Code Online (Sandbox Code Playgroud)
和
> git clone http://myservername/git/projectname.git test/
Cloning into test...
error: The requested URL returned error: 502 while accessing http://myservername/git/projectname.git/info/refs
fatal: HTTP request failed
Run Code Online (Sandbox Code Playgroud)
另请注意,对于任何这些配置,当我尝试使用实际不存在的项目名称进行克隆时,我会收到 502 错误。
有没有人已经成功地做到了这一点?我究竟做错了什么?
谢谢。
更新:
nginx错误日志文件说:
2012/04/05 17:34:50 [crit] 21335#0: *50 connect() to unix:/var/run/fcgiwrap.socket failed (13: Permission denied) while connecting to upstream, client: 192.168.12.201, server: myservername, request: "GET /git/oct_editor.git/info/refs HTTP/1.1", upstream: "fastcgi://unix:/var/run/fcgiwrap.socket:", host: "myservername"
Run Code Online (Sandbox Code Playgroud)
所以我更改了 /var/run/fcgiwrap.socket 的权限,现在我有:
> git clone http://myservername/git/projectname.git test/
Cloning into test...
error: The requested URL returned error: 403 while accessing http://myservername/git/projectname.git/info/refs
fatal: HTTP request failed
Run Code Online (Sandbox Code Playgroud)
这是我现在拥有的 error.log 文件:
2012/04/05 17:36:52 [error] 21335#0: *78 FastCGI sent in stderr: "Cannot chdir to script directory (/usr/lib/git-core/git/projectname.git/info)" while reading response header from upstream, client: 192.168.12.201, server: myservername, request: "GET /git/projectname.git/info/refs HTTP/1.1", upstream: "fastcgi://unix:/var/run/fcgiwrap.socket:", host: "myservername"
Run Code Online (Sandbox Code Playgroud)
我继续调查。
这是我在 Apache 配置中设置的内容(我知道:不是 nginx,但仍然可以帮助你):
SetEnv GIT_PROJECT_ROOT @H@/repositories
SetEnv GIT_HTTP_EXPORT_ALL
SetEnv GITOLITE_HTTP_HOME @H@
ScriptAlias /hgit/ @H@/gitolite/bin/gl-auth-command/
SetEnv GIT_HTTP_BACKEND "@H@/usr/local/apps/git/libexec/git-core/git-http-backend"
Run Code Online (Sandbox Code Playgroud)
(在我的例子中,存储库的存储@H@
路径).gitolite.rc
我没有在您的配置中看到GITOLITE_HTTP_HOME
并GIT_HTTP_BACKEND
定义。
请参阅此处的完整配置。