Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-root routing with Django and Apache

Tags:

apache

django

I'm trying to get Django served by Apache, but I'd like it to have more flexibility than the dumb way I've got it implemented now. At the moment, my httpd_wsgi.conf has this line:

WSGIScriptAlias / /Library/WebServer/Documents/acdc/apache/promotions.wsgi

In my project's urls.py, I have this line:

url(r'^chicken/login/', 'login'),

If I type http://www.example.com/chicken/login into my browser's address bar, I get routed to the appropriate login function. And if all the patterns in urls.py are prefaced with 'chicken' then everything works fine.

What I'd like, though, is to be able to switch the URL at which this app is deployed. So for instance, what if I wanted http://www.example.com/monkey/login to work? Right now I'd have to change all my URLs and all my links, which is dumb. It seems like this should be trivial if I changed WSGIScriptAlias:

WSGIScriptAlias /monkey/ /Library/WebServer/Documents/acdc/apache/promotions.wsgi

then I could just have my URLs look like:

url(r'^login/', 'login'),

and get rid of the coupling. The problem is that after an hour of trial and error and research I can't get it to work. Navigating to http://www.example.com/monkey/login using the just-previous configuration gives me this Apache error in the log:

Target WSGI script not found or unable to stat: /Library/WebServer/Documents/acdc/apache/promotions.wsgilogin

so it looks like the "login" route is just get appended to the promotions.wsgi file that launches my Django app.

To summarize, I'd like to have Apache 'swallow' portions of the URL and feed the rest for pattern-matching with my patterns in urls.py. How do I do this?

like image 566
shanusmagnus Avatar asked Nov 12 '22 12:11

shanusmagnus


1 Answers

For those who want to have 2 WSGIScriptAliases, one of which is root and the other is a subdirectory. Be sure to put them in correct order:

WSGIScriptAlias /game /var/www/game/game.wsgi
WSGIScriptAlias / /var/www/landing/landing.wsgi
like image 186
Berzin Gregory Avatar answered Nov 15 '22 05:11

Berzin Gregory