3

I have a website that I am currently rewriting app-by-app using Django. Server is RedHat. Running Apache 2. Installed mod_wsgi. Everything works fine. Awesome.

If I go to http://www.example.com/ I get to the main site that pre-exists (in PHP).

I have mod_wsgi running and working just fine. If I go to http://www.example.com/django/ I get to my Django powered homepage.

I have several apps that work from that just fine:

All the reverse url lookups work fine - everything is great.

The global entry in Apache's httpd.conf is:

WSGIScriptAlias /django /path/to/django/mysite/mysite/apache/django.wsgi

However, as I roll this out into production, I don't want to have the /django part of the url involved.

So, a request for http://www.example.com/software would run the Django software app.

A request for http://www.example.com/newsletter would run the Django newsletter app.

I can't make http://www.example.com/ redirect to the root Django wsgi application just yet - that will probably happen in a couple months time when the whole site Django rewrite is done.

So, any ideas how I can make my Django apps work in the current setup?

Do I have to create per app wsgi files (eg: /path/to/django/mysite/mysite/apache/software.wsgi and /path/to/django/mysite/mysite/apache/newsletter.wsgi) with per app entries in the httpd.conf file? Such as:

WSGIScriptAlias /software /path/to/django/mysite/mysite/apache/software.wsgi
WSGIScriptAlias /newsletter /path/to/django/mysite/mysite/apache/newsletter.wsgi

I can't seem to find that much specific documentation on this particular style of setup. Most docs assume that you are using one main wsgi file and Django (via urls.py) to broker all requests. I would love that to the case for me, but right now that can't happen.

It might be some Apache directive kung-fu I have to wrangle. If that is the case please let me know.

TIA.

tatlar
  • 3,080
  • 2
  • 29
  • 40

2 Answers2

2

I understand you're rolling out new bits for everything on www.example.com piece by piece. How about setting up the whole Django project in another, new Apache virtualhost container with a new subdomain like new.example.com? You root Django app would be accessible from http://new.example.com, the software app from http://new.example.com/software etc. For the main domain www.example.com, just set up redirects:

www.example.com/django -> new.example.com
www.example.com/software -> new.example.com/software
www.example.com/newsletter -> new.example.com/newsletter

You can test your whole project on the same URL structure it will have after you throw the switch, and throwing the switch becomes merely replacing the ServerName directive in two virtualhosts.

Simon
  • 12,018
  • 4
  • 34
  • 39
0

I had a similar issue, just the other way around. I wanted to replace a django installation part by party with a php-installation.

In Apaches virtual host config for the site use

WSGIScriptAliasMatch ^(/(software|newsletter)) /path/to/django/mysite/mysite/apache/django.wsgi$1

instead of

WSGIScriptAlias /software /path/to/django/mysite/mysite/apache/software.wsgi
WSGIScriptAlias /newsletter /path/to/django/mysite/mysite/apache/newsletter.wsgi

In the urls.py make django believe, that the mount point is the root url / like so:

...
url(r'^software/', include('software.urls')),
url(r'^newsletter/', include('newsletter.urls')),
...

This way, when you finished the site and want to serve everything, including the root url from django, you just need to replace the WSGIScriptAliasMatch entry with

WSGIScriptAlias / /path/to/django/mysite/mysite/apache/django.wsgi

and that will be it.

Check these Q&A for further information:

Django (wsgi) and Wordpress coexisting in Apache virtualhost

Reconfiguring Apache to serve website root from new php source and specific sub-urls from old django site

Community
  • 1
  • 1
Creech
  • 258
  • 2
  • 12