I spent a lot of time figuring out how to make Git over HTTP(S) and Gitweb coexist, but finally got it working.
info
Consider using the
Gitweb method only if you don’t need Git over HTTP(S)
Configuration Method link
Here’s the method I used:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
| server {
listen 80;
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/deimos.fr/server-unified.crt;
ssl_certificate_key /etc/nginx/ssl/deimos.fr/server.key;
ssl_session_timeout 5m;
server_name git.deimos.fr;
root /usr/share/gitweb/;
access_log /var/log/nginx/git.deimos.fr_access.log;
error_log /var/log/nginx/git.deimos.fr_error.log;
index gitweb.cgi;
# Drop config
include drop.conf;
# Git over https
location /git/ {
alias /var/cache/git/;
if ($scheme = http) {
rewrite ^ https://$host$request_uri permanent;
}
}
# Gitweb
location ~ gitweb\.cgi {
fastcgi_cache mycache;
fastcgi_cache_key $request_method$host$request_uri;
fastcgi_cache_valid any 1h;
include fastcgi_params;
fastcgi_pass unix:/run/fcgiwrap.socket;
}
}
|
With this configuration, Git over HTTPS is working (HTTP is redirected to HTTPS) and Gitweb is working too since everything matching gitweb.cgi is correctly routed.
Repository Configuration link
For the Git part, we need to authorize the repositories we want to expose. For this, we need to rename a file in our repository and run a command:
1
2
3
| cd /var/cache/git/myrepo.git
hooks/post-update{.sample,}
su - www-data -c 'cd /var/cache/git/myrepo.git && /usr/lib/git-core/git-update-server-info'
|
Replace www-data with the user that has permissions on the repository. Use www-data so that Nginx has the necessary rights.
Using the Repository link
After this setup, you can clone your repository:
git clone http://www.deimos.fr/git/deimosfr.git deimosfr
Last updated
04 Jan 2013, 17:28 +0200. history