Skip to content

Commit 17c6a71

Browse files
committed
Merge pull request #432 from vitalyq/smart-http
Improve Smart HTTP section
2 parents 9ced5b7 + 4d65a9e commit 17c6a71

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

book/04-git-server/sections/smart-http.asc

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@ If you don't have Apache setup, you can do so on a Linux box with something like
1313
[source,console]
1414
----
1515
$ sudo apt-get install apache2 apache2-utils
16-
$ a2enmod cgi alias env
16+
$ a2enmod cgi alias env rewrite
1717
----
1818

19-
This also enables the `mod_cgi`, `mod_alias`, and `mod_env` modules, which are all needed for this to work properly.
19+
This also enables the `mod_cgi`, `mod_alias`, `mod_env`, and `mod_rewrite` modules, which are all needed for this to work properly.
20+
21+
You’ll also need to set the Unix user group of the `/opt/git` directories to `www-data` so your web server can read- and write-access the repositories, because the Apache instance running the CGI script will (by default) be running as that user:
22+
23+
[source,console]
24+
----
25+
$ chgrp -R www-data /opt/git
26+
----
2027

2128
Next we need to add some things to the Apache configuration to run the `git-http-backend` as the handler for anything coming into the `/git` path of your web server.
2229

@@ -29,36 +36,32 @@ ScriptAlias /git/ /usr/lib/git-core/git-http-backend/
2936

3037
If you leave out `GIT_HTTP_EXPORT_ALL` environment variable, then Git will only serve to unauthenticated clients the repositories with the `git-daemon-export-ok` file in them, just like the Git daemon did.
3138

32-
Then you'll have to tell Apache to allow requests to that path with something like this:
39+
Finally you'll want to tell Apache to allow requests to `git-http-backend` and make writes be authenticated somehow, possibly with an Auth block like this:
3340

3441
[source,console]
3542
----
36-
<Directory "/usr/lib/git-core*">
37-
Options ExecCGI Indexes
38-
Order allow,deny
39-
Allow from all
40-
Require all granted
41-
</Directory>
42-
----
43-
44-
Finally you'll want to make writes be authenticated somehow, possibly with an Auth block like this:
43+
RewriteEngine On
44+
RewriteCond %{QUERY_STRING} service=git-receive-pack [OR]
45+
RewriteCond %{REQUEST_URI} /git-receive-pack$
46+
RewriteRule ^/git/ - [E=AUTHREQUIRED]
4547
46-
[source,console]
47-
----
48-
<LocationMatch "^/git/.*/git-receive-pack$">
48+
<Files "git-http-backend">
4949
AuthType Basic
5050
AuthName "Git Access"
5151
AuthUserFile /opt/git/.htpasswd
5252
Require valid-user
53-
</LocationMatch>
53+
Order deny,allow
54+
Deny from env=AUTHREQUIRED
55+
Satisfy any
56+
</Files>
5457
----
5558

5659
That will require you to create a `.htpasswd` file containing the passwords of all the valid users.
5760
Here is an example of adding a ``schacon'' user to the file:
5861

5962
[source,console]
6063
----
61-
$ htdigest -c /opt/git/.htpasswd "Git Access" schacon
64+
$ htpasswd -c /opt/git/.htpasswd schacon
6265
----
6366

6467
There are tons of ways to have Apache authenticate users, you'll have to choose and implement one of them.

0 commit comments

Comments
 (0)