Hi Kyle,

Thanks for your extensive reply. I was going through the code and had
stumbled upon the SCRIPT_NAME trick when your mail came in and confirmed
that it was indeed possible. In the default admin setup, the logo path
needed to be fixed from '/logo' to '$baseurl/logo', but then it works
fully. I can confirm that it also works on Linux and Windows, not just
Darwin. For folks not using Apache it would be good if your below 'how to'
could mention that the reverse proxy needs to strip the baseurl of the uri
it forwards to the Fossil server (i.e.: '/fossil/index' must be forwarded
as '/index').

However, this is a hack that works by accident. It works because 'server'
and 'cgi' share code paths and the 'server' code flow reads part of the CGI
environment even though it shouldn't. Can you imagine the configuration
headache if one had an unrelated SCRIPT_NAME environment variable and
wasn't aware of this "feature"... Also, the hack fixes the baseUrl to one
defined prefix. Access to a fossil server setup using this hack becomes
unusable from the web if accessed directly as well, nor can multiple
baseurl's be mapped to a single fossil server instance. Whilst I'm quite
happy that the hack fixes my immediate problem, I think a better engineered
solution is preferrable.

First of all, I note that baseUrl relocation in server mode works without
problem as you have established and I can confirm from short experience; so
we are not entering a mine field, it seems. First I thought along the lines
that you point out in your how-to. Later I thought that we should not
overload Fossil with options, especially as everybody will want something a
little different. Instead, it should be the reverse proxy that does all the
work IMHO.

How about using request headers for this? The reverse proxy could add two
custom headers to the forwared request (similar to X-Forwarded-For):
- X-Fossil-Baseurl
- X-Fossil-Repository
Fossil would only look at these when in server mode. The first would
specify the baseurl that is used to relocate all references in html/css
output, and in redirect responses. If no such header exists, it is root
('/'). The first is sufficient for reverse proxying. The second would
specify the repository to use for that request only. If no such header
exists, it is the repository specified on the command line. This would take
care of your generalised repository access.

This would work very well with my own (soon to be published, GPL'ed)
reverse proxy. It would also work very well with Lighttpd, using its
mod_magnet module. Would it be workable with Apache too? (I'm not familiar
with Apache configuration).

Paul

On Thu, 28 Jan 2010 11:53:36 -0800, Kyle McKay <mack...@gmail.com> wrote:
> Paul,
> 
> I'm running a fossil server behind an Apache reverse proxy quite  
> happily.  I've been meaning to add something to the wiki cookbook  
> about this but just haven't got around to it yet.
> 
> I'm doing this because:
> 
> 1. I want a fossil UI to be always on and available via my web server
> 2. I want the fossil server to run as a different user account than  
> the web server processes
> 3. I don't want to use any suid programs (i.e. suExec)
> 
> My apache web server is setup so that:
> 
>    http://my_server_name/fossil
> 
> Is reverse proxied to the fossil server process that is running as a  
> daemon on a separate port
> 
>    http://my_server_name/anything-other-than-fossil-here
> 
> Serves up whatever else would normally be served on my server.
> 
> To make this work (I'm running on Darwin which is very Unix like) you  
> need to do these two things (the examples assume you have a bash shell):
> 
> 1. Start your fossil server daemon running with a shell script like this
> 
>     #!/bin/sh
>     export SCRIPT_NAME=/fossil
>     fossil server -P 8000 full_path_to_fossil_respository_here &
> 
> If you want to start the fossil server in its own process group, add  
> this line:
> 
>     set -m
> 
> at the beginning of the script and add this line:
> 
>     disown
> 
> at the end and you probably want to redirect fossil input, output and  
> error to /dev/null as well so the final script to do all of this would  
> look like (adding nohup also to make it immune to SIGHUP):
> 
>     #!/bin/bash
>     set -m
>     export SCRIPT_NAME=/fossil
>     nohup fossil server -P 8000 full_path_to_fossil_respository_here \
>         </dev/null >/dev/null 2>&1 &
>     disown # this is a bashism
> 
> 2. Add this configuration section to your Apache configuration
> 
>     ProxyPass /fossil http://machine_your_fossil_server_is_running_on: 
> 8000
>     ProxyPreserveHost On
>     # ProxyPreserveHost is required since fossil inspects the Host value
>     # and without it fossil-generated links will point directly to  
> fossil
>     # instead of the Apache server
> 
> 3. Access your fossil server like this:
> 
>     http://machine_apache_is_running_on/fossil
> 
> 4. Optionally add a firewall rule to limit connections to the fossil  
> server to only those coming from the Apache server machine (be nice if  
> fossil had a loopback-only setting similar to postfix's to bind its  
> socket listener to only localhost IPv4/IPv6 interfaces).
> 
> If you want your fossil URL to look like http://some_machine/foo/bar/ 
> scm you need would change the above example lines for starting your  
> fossil server and setting your Apache configuration as follows:
> 
>     SCRIPT_NAME=/foo/bar/scm
>     ProxyPass /foo/bar/scm http:// 
> machine_your_fossil_server_is_running_on:8000
> 
> Similarly you can change the port the fossil server runs on just as  
> easily.
> 
> It turns out that since fossil already handles running from an  
> arbitrary web location as a cgi script, it quite happily will still  
> use that arbitrary location when running as a server if you provide it  
> via SCRIPT_NAME.
> 
> I wish there was functionality something like this though:
> 
>     fossil server -P 8000 --ext .fsl  
> path_to_directory_containing_.fsl_repositories
> 
> Where a single fossil server could serve up multiple fossil  
> repositories.  You would just point it to the parent directory and  
> tell it what repository extension to look for and then it would insert  
> an additional element into the URL using the base name of the fossil  
> repository minus the extension.  So if you had these repositories on  
> your system:
> 
>    /some/directory/repository1.fsl
>    /some/directory/repository2.fsl
> 
> And started the fossil server like this:
> 
>     fossil server -P 8080 --ext .fsl /some/directory
> 
> Then you could access repository1.fsl like this:
> 
>     http://localhost:8080/repository1
> 
> and repository2.fsl like this:
> 
>     http://localhost:8080/repository2
> 
> and as a bonus you could get a list of available repositories with this:
> 
>     http://localhost:8080/
> 
> (And, of course, still use the SCRIPT_NAME trick to change the URL  
> location if you like.)
> 
> I believe a relatively simple Perl or Python server script could use  
> the fossil http command to implement the multiple repository server  
> relatively easily since the SCRIPT_NAME technique also works with the  
> fossil http command.  Hmmm, I might just have to write that script  
> later today.
> 
> Kyle
> 
> On Jan 28, 2010, at 04:00, Paul Ruizendaal wrote:
>> It may be subtler and easier than I first thought:
>>
>> Fossil already uses the host information from the Host: header, not  
>> from
>> its own IP. When in CGI mode, it already relocates all its absolute
>> references to include the prefix of the cgi script location.
>>
>> When running as server Fossil does not do the above relocation but  
>> keeps
>> everyting based at root ('/'), regardless of the path in the request  
>> uri.
>> Is there a reason that makes fossil CGI style relocation a bad idea  
>> for a
>> fossil running in server mode?
>>
>> Paul
>>
>> ======
>>
>> I just tried to put Fossil (running as server) behind a reverse proxy
>> (home grown, but similar to "Pound").
>>
>> That doesn't work very well, because Fossil prefixes all paths in its
>> output with a full baseURL (as seen by Fossil). The client can't use  
>> that
>> as the reverse proxy maps an entirely different prefix to the Fossil
>> server
>> instance. I think the html/css output by Fossil should use relative  
>> paths,
>> not absolute paths.
>>
>> Next to the above, also the 301 Redirect repsonses have the wrong  
>> url, but
>> that is as per the http RFC: it is a reasonable job for a reverse  
>> proxy to
>> rewrite the Location: header of a 301 response.
>>
>> Before I attempt this rather massive patch: Richard, any remarks?
>>
>> Paul
_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to