UserDir and WSGI

59 views
Skip to first unread message

Cristian P

unread,
Jan 7, 2017, 12:35:47 AM1/7/17
to modwsgi
Hi 

I have a spent week looking online on how to make userdir module (www.example.com/~username) work when 
the root page is a wsgi application (WSGIScriptAlias / /path/to/wsgi.py).

I am using Django (1.10.4) with on Apache (2.4.18) with mod-wsgi enabled. 

I have read multiple post written by Graham addressing this but I can't wrapped my head on how I would 
implemented as I am just getting started in web development.
I am trying to let apache handle all userdir pages with no wsgi capabilities and if possible a set of list of other sub urls 
should be handle by apache and bypass wsgi.

I have seen posts that suggest changes to the wsgiscript but all the post involve an application method which is not implemented
when using the django supply script

The wsgi.py is :
"""
WSGI config for website project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "website.settings")
application = get_wsgi_application()

Thank you any help would be greatly appreciated
Cristian

Graham Dumpleton

unread,
Jan 7, 2017, 12:41:17 AM1/7/17
to mod...@googlegroups.com
What mod_wsgi version are you using?

Graham

--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To post to this group, send email to mod...@googlegroups.com.
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Graham Dumpleton

unread,
Jan 7, 2017, 5:26:11 AM1/7/17
to mod...@googlegroups.com
Actually the mod_wsgi version isn't going to matter. Had forgot that the default behaviour is something that just can't be changed and it actually mirrors how Alias in Apache works.

There are couple of ways to achieve what you want. The first is that instead of:

    WSGIScriptAlias / /Users/graham/Projects/mod_wsgi/tests/environ.wsgi

you use:

    WSGIScriptAliasMatch "^/([^~].*)?$" /Users/graham/Projects/mod_wsgi/tests/environ.wsgi/$1

The second way is bit more convoluted and involves use of mod_rewrite, a DocumentRoot directory and fiddling stuff in the WSGI application script file. Lets see though whether the first way suffices.

What that WSGIScriptAliasMatch does is to pass through anything that doesn't start with '/~' to the WSGI application.

Very import is how the matched URL is added back to the target WSGI script file provided as last argument. If you don't do that then SCRIPT_NAME/PATH_INFO will not be constructed in way required.

Graham

Cristian P

unread,
Jan 7, 2017, 11:58:05 AM1/7/17
to modwsgi
Thank you so much that work perfectly. 
Is there a proper way to create list of Aliases that should bypass wsgi besides multiple of these statements.

The second way sounds interesting, how would the wsgi script be able to pick up the path_info?

Thank you so much for the fast response

Regards 
Cristian

Graham Dumpleton

unread,
Jan 7, 2017, 3:55:17 PM1/7/17
to mod...@googlegroups.com

> On 8 Jan 2017, at 3:58 AM, Cristian P <cristian...@gmail.com> wrote:
>
> Thank you so much that work perfectly.
> Is there a proper way to create list of Aliases that should bypass wsgi besides multiple of these statements.
>
> The second way sounds interesting, how would the wsgi script be able to pick up the path_info?

URLs handled by mod_userdir are a special case. The default order has to be the way it is else you wouldn't be able to use WSGI applications setup using AddHandler inside of a users personal directory.

For any other aliases, just use the Alias directive as Alias will always override WSGIScriptAlias.

Thus if you need to have static files at a sub URL, or a directory with PHP files in it, you would have:

Alias /suburl /some/path/to/static/files
WSGIScriptAlias / /some/path/to/wsgi.py

Note that order actually doesn't matter here as Alias truly always overrides WSGIScriptAlias, not done by order in file.

Order is important in a case like:

WSGIScriptAlias /suburl /some/other/path/to/wsgi.py
WSGIScriptAlias / /some/path/to/wsgi.py

where the deepest sub URLs should be first as they are matched in order within set of WSGIScriptAlias directives.

Same occurs for Alias, so if have more than one of those, list in order so that most specific is first.

Graham
Reply all
Reply to author
Forward
0 new messages