How do you deal with the "trailing slash problem" when deploying with mod_wsgi?

17 views
Skip to first unread message

Wyatt Baldwin

unread,
Dec 15, 2010, 10:45:10 PM12/15/10
to pylons-discuss
In an Apache VirtualHost, I have some mod_wsgi configuration that
looks like this for a handful of apps:

WSGIDaemonProcess acid user=me group=cooldoods display-name=acid
WSGIScriptAlias /app/acid /somewhere/acid/parts/wsgi_app/wsgi
<Location /app/acid>
WSGIProcessGroup acid
</Location>

Just to make the example complete, I also have this in the Apache
server config, outside of any VirtualHost:

LoadModule wsgi_module modules/python26-mod_wsgi.so

# Specifies the directory to use for WSGI daemon sockets. This
can't be
# defined in a VirtualHost section.
WSGISocketPrefix run/wsgi

[Any critique of this config would be appreciated as, as this is my
first time with mod_wsgi, but that's not the point of this post.]

The trailing slash issue comes up when a user visits the root URL but
omits the trailing slash. For the example above, that would be this
URL:

https://example.com/app/acid

mod_wsgi doesn't have a problem with this, but it passes on an empty
value for PATH_INFO. Routes chokes on this, though, because there's
nothing to match against.

Previously, when I was proxying to `paster serve`, I was using Paste's
PrefixMiddleware, which I just discovered will tack on the trailing
slash for you. I'm not sure I like that, nor am I sure that it's
strictly correct.

I'm not sure, though, so maybe Routes should treat empty PATH_INFO the
same as a single /. It doesn't feel right to me, but maybe it would
be OK.

My current solution is the following, which merely redirects from a
root URL without a trailing slash to one with a trailing slash. This
won't apply to application sub-URLs that include a path.

RewriteRule ^/app/([^/]+)$ /app/$1/ [R,L]

This feels good because there's a single, canonical URL addressing the
root of the site.

My only question is how others have solved this problem--in general
and particularly when deploying with mod_wsgi.

I also thought the config above might be useful to somebody as an
example of setting up mod_wsgi in daemon mode for running a Pylons
app. I actually had a hard time finding simple, complete examples.
Reply all
Reply to author
Forward
0 new messages