git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: "José María Escartín Esteban" <ripero84@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Static gitweb content when using pathinfo
Date: Tue, 17 Apr 2012 14:30:52 +0200	[thread overview]
Message-ID: <201204171430.52650.jnareb@gmail.com> (raw)
In-Reply-To: <4F8C384C.2040109@gmail.com>

On Mon, 16 Apr 2012, José María Escartín Esteban wrote:
> On 14/04/12 19:19, Jakub Narebski wrote:
>> On Thu, 5 Apr 2012, Jakub Narebski wrote:
>>> On Thu, 5 Apr 2012, José María Escartín Esteban wrote:

>>> There might be problem if you configured your web server to serve gitweb
>>> using it as a handler for subdirectory, so the script name does not need
>>> to appear in URL, e.g.
>>>
>>>   http://localhost/cgi-bin/gitweb
>>>
>>> which would require the following base element
>>>
>>>   <base href="http://localhost/cgi-bin/gitweb/" />
>>
>> [...]
>>
> 
> Yes, that was precisely the problem.

Note that you won't have problem with `http://localhost` as base url
(without any directory), or in more realistic case using virtual host
rather than virtual directory.  The problem is that without '/' the
path part of $base_url is stripped of last element.

Just for completeness.

[...]
> This addition to the man page would of course have been useful, since it took me
> a while to detect that the problem was a missing slash in the base url.
> However, it would not have solved completely my problem, and for me the best has
> been to add the line of code you proposed in the previous email.

So how about the proposed updated addition at the end of this email?

> I am running a Debian testing (wheezy) server, so the distro gitweb files are:
> 
> 	/etc/apache2/conf.d/gitweb
> 	/etc/gitweb.conf
> 	/usr/share/gitweb/gitweb.cgi
> 	/usr/share/gitweb/index.cgi -> /usr/share/gitweb/gitweb.cgi
> 	/usr/share/gitweb/static/*
> 
> I am using two sets of git repositories, and each of the sets works through a
> particular gitolite user:
> 
> 	user     home
> 	----------------------
> 	git      /srv/project
> 	mygit    /srv/mygit
> 
> I wanted that different groups of people were able to browse the 'project' repos
> (in fact it is a mirror from the main project server) from
> 	http://server.example.com/project/ ,
> and the 'mygit' repos from
> 	http://server.example.com/mygit/ .
> And I wanted to keep urls as short and easy as possible, and to avoid
> proliferation of configs as much as possible.

I think that is this "two sets" that created configuration with a problem.
 
> The setup I came up with was to link
> 
> 	/srv/www/project -> /usr/share/gitweb
> 	/srv/www/mygit -> /usr/share/gitweb
> 
> and to use the following configuration files:
> 
> ######### /etc/apache2/conf.d/gitweb ##################
> <Directory /srv/www/project>
>         SetEnv  GITWEB_PROJECTROOT      /srv/git/
>         SetEnv  GITWEB_CONFIG           /etc/gitweb.conf
[...]
> #######################################################
> 
> ######### /etc/gitweb.conf ############################
> $projectroot = $ENV{'GITWEB_PROJECTROOT'}."repositories";
> $git_temp = "/tmp";
> $projects_list = $ENV{'GITWEB_PROJECTROOT'}."projects.list";
> @diff_opts = ();
> $feature{'pathinfo'}{'default'} = [1];
> $feature{'highlight'}{'default'} = [1];
> $projects_list_description_width = 50;
> #######################################################

A question: why not have

          SetEnv  GITWEB_PROJECTROOT      /srv/git

and use

  $projectroot = "$ENV{'GITWEB_PROJECTROOT'}/repositories";
  $projects_list = "$ENV{'GITWEB_PROJECTROOT'}/projects.list";
 

BTW. what is this $git_temp?  Is it modified gitweb, because core one
doesn't need to use temporary directory for anything nowadays?

A tip: you can use GITWEB_CONFIG_COMMON for the common part of
configuration and separate GITWEB_CONFIG for per-instance configuration.
Though I am not sure if it would help in your case.  It requires
modern gitweb. though.

> Probably there are better ways to implement this, but at least this seems to
> work, once I have added
> 
> 	$base_url .= '/' unless ($base_url =~ m!/$!);
> 
> to /etc/gitweb.conf .

-- >8 ---------- >8 --
Subject: [PATCH] gitweb.conf(5): When to set $base_url

Add a paragraph to description of $base_url variable in gitweb.conf(5)
manpage explaining when and why one might need to set it, and how.

Based-on-report-by: José María Escartín Esteban <ripero84@gmail.com>
Signed-off-by: Jakub Narębski <jnareb@gmail.com>
---
 Documentation/gitweb.conf.txt |   24 ++++++++++++++++++++++++
 Documentation/gitweb.txt      |    4 ++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/Documentation/gitweb.conf.txt b/Documentation/gitweb.conf.txt
index 7aba497..4716a0f 100644
--- a/Documentation/gitweb.conf.txt
+++ b/Documentation/gitweb.conf.txt
@@ -559,6 +559,30 @@ $base_url::
 	PATH_INFO.  Usually gitweb sets its value correctly,
 	and there is no need to set this variable, e.g. to $my_uri or "/".
 	See `$per_request_config` if you need to override it anyway.
++
+You would need to set this variable when using path_info-based URLs
+while using gitweb as a directory handler (which means that full path
+to browse repositories looks like `http://git.example.com/gitweb`
+rather than looking like `http://git.example.com/gitweb/gitweb.cgi`).
+You can find yourself in this situation (gitweb as directory handler)
+when configuring gitweb to use FastCGI interface as shown in
+"Webserver configuration" section on linkgit:gitweb[1] manpage.
++
+If static files are served from 'static' subdirectory of directory
+the gitweb script is handler for, with default URLs of static files
+(e.g. `$logo` is `static/git-logo.png`), then you would need to ensure
+that `$base_url` ends with slash to denote that it is directory, to
+work correctly:
++
+----------------------------------------------------------------------
+$base_url .= '/' unless ($base_url =~ m!/$!);
+----------------------------------------------------------------------
++
+For example if gitweb URL is `http://git.example.com/gitweb`, and
+static files are available in `http://git.example.com/gitweb/static/`
+then `$base_url` must end up to be `http://git.example.com/gitweb/`
+(with trailing slash) for e.g. `static/git-logo.png` relative link
+to refer to `http://git.example.com/gitweb/static/git-logo.png`.
 
 
 CONFIGURING GITWEB FEATURES
diff --git a/Documentation/gitweb.txt b/Documentation/gitweb.txt
index b394ecc..c3db66a 100644
--- a/Documentation/gitweb.txt
+++ b/Documentation/gitweb.txt
@@ -473,6 +473,10 @@ With that configuration the full path to browse repositories would be:
 
   http://server/gitweb
 
+Note that for this configuration `$base_url` must be set as described
+in linkgit:gitweb.conf[5] for gitweb to correctly serve static files
+with path_info links.
+
 As PSGI using plackup
 ~~~~~~~~~~~~~~~~~~~~~
 Gitweb can run as PSGI app (via emulation with *CGI::Emulate::PSGI*(3pm)).
-- 
1.7.9

  reply	other threads:[~2012-04-17 12:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-05 13:54 Static gitweb content when using pathinfo José María Escartín Esteban
2012-04-05 21:14 ` Jakub Narebski
2012-04-14 17:19   ` Jakub Narebski
2012-04-16 15:18     ` José María Escartín Esteban
2012-04-17 12:30       ` Jakub Narebski [this message]
2012-04-24  7:01         ` José María Escartín Esteban

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201204171430.52650.jnareb@gmail.com \
    --to=jnareb@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=ripero84@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).