Project

General

Profile

mod_fastcgi and trac

Added by tdussa over 15 years ago

Hi everybody,

I'm probably suffering from acute blindness, but I am flat out of ideas.

I am trying to configure lighty + trac so that trac is run by mod_fastcgi.
This by itself is easy and works. However, I'd like for trac to be run
right from the root URL, i. e., say, http://my.server.com/ should
immediately call trac and return the available project listing. Again,
this works, but this is also where the trouble starts.
Now, when I click a project name, then I am correctly pointed to
http://my.server.com/Projectname. However, this URL again just returns
the available projects page, instead of the Project itself. Now clicking
Project again goes to http://my.server.com/Projectname/Projectname and
finally gets me to the project.

Now, the problem is obvious. Lighty obviously directs all URLs to the
trac instance running as fastcgi code, as it should, but somehow one link
level is swallowed.

I'm not even sure whether this is a trac or a lighty problem, but I did
read the lighty docs, and they said to include a url.alias command
("" => "/path/to/trac.fcgi") specifically in this situation. Inserting
this url.alias did not help, and in fact I don't even have a clear
picture of why the url.alias should be necessary, so I hope that at least
someone might be able to give me a pointer as to what that line is necessary
for.

I'm running lighty 1.4.19 on FreeBSD 7.0-RELEASE. The revelant section of
lighttpd.conf is given below; the rest of the config file is unchanged
except for the necessary module loads.

I'm probably missing something dead obvious...

Any comments would be appreciated.

Thanks a lot!

Cheers,
Toby.

@
alias.url = (
"/chrome/common/" => "/usr/local/share/trac/htdocs/",
)

  1. rewrite for multiple svn project
    url.rewrite-final = (
    "^/[^/]+/chrome/common/(.*)" => "/chrome/common/$1",
    )

$HTTP["url"] =~ "^/chrome/" { # no fastcgi
} # end of $HTTP["url"] =~ "^/chrome/"
else $HTTP["url"] =~ "^/" {
fastcgi.server = (
"/" => (
(
"bin-path" => "/usr/local/share/trac/cgi-bin/trac.fcgi",
"socket" => "/tmp/trac.sock",
"check-local" => "disable",
"disable-time" => 1,
"min-procs" => 1,
"max-procs" => 1,
"bin-environment" => (
"TRAC_ENV_PARENT_DIR" => "/usr/local/trac",
),
),
),
)
} # end of $HTTP["url"] =~ "^/"
@


Replies (3)

RE: mod_fastcgi and trac - Added by hoffie over 15 years ago

Well, it's probably neither a bug in trac nor in lighty, it's just that lighty handles FastCGI apps at the root path (/) in a way which trac does not expect. There is no fix for this, but you can work around it, e.g. by having your FastCGI app at /bla/ and adding a rewrite rule .* => /bla$0 or somethign along the lines. :)

RE: mod_fastcgi and trac - Added by tdussa over 15 years ago

I see. So what are the evil twists that lighty does with the root path of FCGI apps? Besides, if it won't work anyway, what is the point of specifically adding extra instructions for this particular case in the trac-on-lighty setup wiki page?

Besides, I did already try what you suggest: adding a rewrite rule to the URL and having trac listen to the long URL. However, then all the links in the pages "further down" do show the artificially-inserted workaround URL part, which will most probably serve to confuse the user.

Another workaround, of course, is having the trac FCGI listen to, say, "/trac", and redirecting the browser from "/" to "/trac". Alas, while this works perfectly, it is not quite what I want.

So, if you have more information on this, I'd greatly appreciate your comments!

Thanks for your reply!

Cheers,
Toby.

RE: mod_fastcgi and trac - Added by tweener over 15 years ago

Hi to everyone.
tdussa wrote:

So, if you have more information on this, I'd greatly appreciate your comments!

I just had the same problem lately. The best I came up with is to hack Trac a little bit. Don't know the version You are using, but with the latest SVN checkout I was able to fix the issue by modifying file <path to trunk>/trac/web/main.py like that:

--- trac/web/main.py    (revision 7647)
+++ trac/web/main.py    (working copy)
@@ -351,6 +351,9 @@
             environ['SCRIPT_NAME'] = script_url
         elif script_url.endswith(path_info):
             environ['SCRIPT_NAME'] = script_url[:-len(path_info)]
+    if os.getenv("TRAC_LIGHTTPD_ROOT_WORKAROUND"):
+       environ['PATH_INFO'] = environ['SCRIPT_NAME'] + environ['PATH_INFO']
+       environ['SCRIPT_NAME'] = os.getenv('TRAC_LIGHTTPD_ROOT_WORKAROUND')

     # If the expected configuration keys aren't found in the WSGI environment,
     # try looking them up in the process environment variables

Now I just had to use it in lighty's FastCGI config (it's the TRAC_LIGHTTPD_ROOT_WORKAROUND line):
fastcgi.server = ( "/" =>
                        ("trac" =>
                                (
                                        "socket" => var.trac-socket,
                                        "check-local" => "disable",
                                        "max-procs" => 6,
                                        "bin-path" => "/packages/repos/trac/trunk/cgi-bin/trac.fcgi",
                                        "bin-environment" =>
                                        (
                                                "TRAC_ENV_PARENT_DIR" => var.trac-env-parent-dir,
                                                "TRAC_ENV_INDEX_TEMPLATE" => var.trac-env-list-dir + "/index.html",
                                                "PYTHON_EGG_CACHE" => "/tmp/python-egg-trac",
                                                "TRAC_LIGHTTPD_ROOT_WORKAROUND" => "/" 
                                        )
                                )
                        )
)

Quick restart and it worked. I know it's an ugly hack but it's the only one I got for now. It's a 5 min. thing, so You could give it a try.

Regards
J.

And the most important one: "Thanks for Lighty. It rocks!". The support is not bad too ;P.

    (1-3/3)