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).
My current configuration looks like this.
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;
}
}
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/
The exact error I receive upon running git clone http://my.domain.com/repo.git
:
Cloning into 'repo'... fatal: unable to access ' http://my.domain.com/repo.git ': The requested URL returned error: 500
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"
The URL's error log is empty.
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.
UPDATE #1
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 [...]
}
The result is now that when I try git clone http://my.domain.com/repo.git
I get the following output in git bash:
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?
But I can reach both http://my.domain.com
and http://my.domain.com/repo.git
in the browser
Update #2
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.
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;
}
}
This allowed me to properly do a git clone
and git pull
without any errors, but git push
would give me the following error
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 '
Update #3
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.