我正在嘗試使用 Nginx 設定 git-http-backend,但是在浪費了 24 小時時間並閱讀了我能讀到的所有內容之後,我認為這個配置應該可以工作,但不能。
server {
listen 80;
server_name mydevserver;
access_log /var/log/nginx/dev.access.log;
error_log /var/log/nginx/dev.error.log;
location / {
root /var/repos;
}
location ~ /git(/.*) {
gzip off;
root /usr/lib/git-core;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
include /etc/nginx/fastcgi_params2;
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 /var/repos;
fastcgi_param PATH_INFO $1;
#fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
}
}
/etc/nginx/fastcgi_params2 的內容
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param REMOTE_USER $remote_user;
# required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
但配置似乎不起作用
$ git clone http://mydevserver/git/myprojectname/
Cloning into myprojectname...
warning: remote HEAD refers to nonexistent ref, unable to checkout.
我可以請求一個不存在的項目,我會得到相同的答案
$ git clone http://mydevserver/git/thisprojectdoesntexist/
Cloning into thisprojectdoesntexist...
warning: remote HEAD refers to nonexistent ref, unable to checkout.
如果我將 root 更改為 /usr/lib,我將收到 403 錯誤,並且該錯誤將報告到 nginx 錯誤日誌:
2011/11/23 15:52:46 [error] 5224#0: *55 FastCGI sent in stderr: "Cannot get script
name, is DOCUMENT_ROOT and SCRIPT_NAME set and is the script executable?" while
reading response header from upstream, client: 198.168.0.4, server: mydevserver,
request: "GET /git/myprojectname/info/refs HTTP/1.1", upstream:
"fastcgi://unix:/var/run/fcgiwrap.socket:", host: "mydevserver"
我的主要問題是此配置的正確根值。也許存在一些權限問題。
筆記:
/var/repos/ 由 www-data 擁有,包含資料夾位元 git bare repos。
所有這些都可以使用 ssh 完美運行。
如果我使用瀏覽器http://mydevserver/git/myproject/info/refs它由 git-http-backend 回答,要求我發送命令。
/var/run/fcgiwrap.socket 有 777 權限。
答案1
向下移動fastcgi_pass
;應該是最新的線路。
首先你應該設定參數,然後才可以fastcgi_pass
,否則你將無法獲得設定的環境。
fastcgi_pass unix:/var/run/fcgiwrap.socket;
答案2
嘗試更改設定檔中兩行之間的順序:
include /etc/nginx/fastcgi_params2;
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
答案3
這可能是 debian scrap (1.0-1+squeeze1) 上發現的 fcgiwrap 版本的錯誤。看http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=698071
升級到 fcgiwrap 1.0.3-3(在 debian 測試中發現)解決了我的問題。這是我使用的配置(注意我不需要定義“root”):
server {
listen 80;
server_name mydevserver;
access_log /var/log/nginx/dev.access.log;
error_log /var/log/nginx/dev.error.log;
location ~ /git(/.*) {
gzip off;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
include /etc/nginx/fastcgi_params2;
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
fastcgi_param GIT_HTTP_EXPORT_ALL "";
fastcgi_param GIT_PROJECT_ROOT /var/repos;
fastcgi_param PATH_INFO $1;
}
}