1

How do I make a django website (in a apache/mod_wsgi/django setup) which is configured to serve from the root url, serve only for specific sub-url but not the root url? The root url shall be served from a new source (php). All this with a minimum of reconfiguration.

Currently the condensed virtualhost config looks like this

<VirtualHost *:80>
    ServerAdmin admin@mysite.com
    ServerName mysite.com

    # mappings to django
    WSGIScriptAlias / /opt/mysite/mysite.wsgi
    <Directory /opt/mysite>
        Order allow,deny
        Allow from all
    </Directory>

    # mappings to wordpress 
    Alias /wp/ /var/www/mysiteWP/
    <Location "/var/www/mysiteWP/">
            Options -Indexes
    </Location>
    Alias /show/ /var/www/mysiteWP/
    Alias /collection/ /var/www/mysiteWP/
</VirtualHost>

As you can see django and php(wordpress) are running side by side. Wordpress just serving mysite.com/show/ and mysite.com/collection/. Django is serving the rest, including the root url mysite.com. This configuration works.

What I want to do now, is, I want to make wordpress serve everything except some specific urls which should be served by django. E.g. django should just serve mysite.com/shop/ and mysite.com/news/ but nothing else, also excluding mysite.com.

How would I do this with a minimum of reconfiguration?

Thanks for your answers and hints.

Creech
  • 258
  • 2
  • 12
  • I did a similar thing but my frontend was nginx. The configuration of url routing in the nginx.conf is similar to the way url routing happens in django, top-to-bottom. Not an answer but: check out nginx as your frontend. It brings sanity to the mix. – Árni St. Steinunnarson Nov 07 '14 at 11:37
  • @Beltiras: Thx. I will delve into that if I do not find any solution. There needs to be some way to do that with Django. – Creech Nov 10 '14 at 07:50
  • 1
    @Creech: Did you ever find a solution? If so, then please post it as an answer to your own question. Thank you. – dotancohen Mar 08 '15 at 11:29

1 Answers1

0

Props to Graham Dumpleton. He answered another question of the exact same kind in this Q&A: Django (wsgi) and Wordpress coexisting in Apache virtualhost.

In short, after configuring Apache so the root url is served from php, the solution to route specific sub urls to django, but making it think its mount point is still the root, is WSGIScriptAliasMatch. To this (example)problem the simple addition to the apache virtual host config was this:

WSGIScriptAliasMatch ^(/(shop|news)) /opt/mysite/mysite.wsgi$1

The whole virtual host config for this example is:

<VirtualHost *:80>
    ServerAdmin admin@mysite.com
    ServerName mysite.com

    # mappings to django
    WSGIScriptAliasMatch ^(/(shop|news)) /opt/mysite/mysite.wsgi$1
    <Directory /opt/mysite>
        Order allow,deny
        Allow from all
    </Directory>

    # mappings to wordpress 
    DocumentRoot /var/www/mysiteWP/
    <Location "/var/www/mysiteWP/">
            Options -Indexes
    </Location>
</VirtualHost>
Community
  • 1
  • 1
Creech
  • 258
  • 2
  • 12