On Sat, Jul 02, 2022 at 10:46:44PM -0700, Alan Young wrote:

> I am a new git learner and just set up a git server using git-http-backend 
> and Apache.
> Following the official doc(git-http-backend Documentation 
> <https://git-scm.com/docs/git-http-backend>), the httpd.conf can be simple:
> 
> SetEnv GIT_PROJECT_ROOT /var/www/git
> SetEnv GIT_HTTP_EXPORT_ALL
> ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
> # ...something else...
> 
> My question is about the ScriptAlias and git-http-backend, the 
> /usr/libexec/git-core/git-http-backend is an executable program and of 
> course, a file. But in the configuration, it seems to a directory. One URL 
> like http://example.com/git/foo.git should start an CGI program located in 
> /usr/libexec/git-core/git-http-backend/foo.git, which in my view can't 
> exist in the file system.
> 
> Can anyone help me figure this out?

IMO this question is not about Git but rather about Apache.

My sysadmin skills are rusty but I seem to recall the reasoning behind how
ScriptAlias works in this case is like follows:

 - If one wants their alias - be it a "plain" Alias or ScriptAlias - to match
   "whole subpaths", they need to end the URL-path (the "what to match" part)
   of the alias to end in a slash.

   This is needed because and URL-path like "/images" in an alias would also
   match URLs with path components such as "/images-and-words/foo.txt" which
   most of the time is not what is needed.

 - When one sets the URL-path of a ScriptAlias to deal with Git repositories
   to something like "/git/", one must very well understand that this entry
   will match only _the beginning_ of the real URL Apache will serve when
   a request to interact with a Git repository will be made - at the very
   least it will include the actual name of the repository.
   I mean, when you will request http://example.com/git/foo.git,
   the mod_alias (or mod_cgi? It doesn't really matter) will match
   "/git/foo.git" against your "/git/" pattern. Also note that the
   repositories may have more complicated structure - for instance, nothing
   precludes you from using "/git/whatever/nested/structure/foo.git".

 - When Apache processes a request using a matching ScriptAlias directive,
   it basically substitutes your URL-path with the complete contents
   of the "right-hand" string. In your case, "/git/foo.git" will be
   replaced by "/usr/libexec/git-core/git-http-backend/foo.git" and then
   looked up on the filesystem.

   I do not know the specifics - whether the search will start with the full
   resulting pathname and then back out until it finds something runnalbe or
   whether it goes the other way round but the end result will be Apache
   locating your git-http-backend binary and _the rest_ of the URL-path
   will be served to it in the PATH_INFO (or PATH_TRANSLATED - I cannot
   recall) env. variable, and that path will start with the leading slash
   which, in your case, will be "/foo.git".

The key takeaway here is that if there were no traling slash in the right-hand
side string of the ScriptAlias directive, the resulting path would be
"/usr/libexec/git-core/git-http-backendfoo.git" which would have failed to be
processed.

To reiterate, I _think_ that the apparently puzzling approach to setting up
ScriptAlias directive suggested by the git-http-backend docs stems from the
fact the way that directive works does not match the way most readers think
they works. It's logical to think that when a ScriptAlias directive had
matched, the server should look up the binary listed in the right-hand part of
the directive and call it but in reality the server substitutes the right-hand
part for the matched URL-path first and then performs the filesystem lookups.


Having said that, I'd note that my analysis may completely miss the point so I
would ask on the Apache mailing list.
If you will do so, please drop a line about that in this thread - I, for one,
would like to hear what Apache experts have to say on this, too.

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/git-users/20220704105241.igjvbsphmjhyyrkl%40carbon.

Reply via email to