Despite all the links I've found on how to configure git/nginx to get my repos, I can't make them work.
I followed this tutorial, Git repository over HTTP WebDAV with nginx, but the user/password restriction doesnt' work. Anyone can clone the repository.
I'm from a configuration using SVN + Apache + DAV_SVN, with a file for password (created with htpasswd), and a file for the authz. I'd like to do the same, using git+nginx. How's that possible ?
Thanks for your help!
Here is a full configuration for Git over HTTP, with TLS encryption, Basic Auth, and GitWeb (a very simple repositories viewer). I assume that the repositories' root is in /home/git.
You have to install Git, Gitweb and FastCgiWrap :
For TLS, I use Let's Encrypt free certificates.
To access Gitweb, just browse to git.YOURDOMAIN.com. You will also need to configure it to set the repositories' root :
In order to get HTTP Basic Auth, you have to use the
htpasswd
command to add users to/etc/nginx/.htpasswd
:Remove the
-c
switch the next time you run the command, because it only creates the file (Nginx doesn't have a .htpasswd file by default in its configuration directory).If you want something more complex, powerful, GitHub-like, check Gitlab.
Take a look at the following article, http://www.toofishes.net/blog/git-smart-http-transport-nginx/
It provides a sample nginx config:
What this does is pass your repo which is located after /git in the url, to
/usr/lib/git-core/git-http-backend
. Example,http://git.mydomain.com/git/someapp
would point to thesomeapp
repository. This repo would be located in/srv/git/someapp
as defined in thefastcgi_param
ofGIT_PROJECT_ROOT
and can be changed to fit your server.This is very useful and you can apply
HttpAuthBasicModule
to nginx to password protect your repo's access via HTTP.Edit: If you are missing
git-http-backend
, you can install thegit-core
package on Ubuntu/Debian or on RPM based platforms look at How can git be installed on CENTOS 5.5?