I am trying to configure Apache to host a Django webservice and a PHP website.
All URLs with the pattern www.mysite.com/api
should be directed to the Django service. All other URLs (e.g. www.mysite.com
) should be directed to the PHP website.
My virtual host config looks like this:
... WSGIScriptAlias /api /var/www/mysite.com/apache/django.wsgi <Directory /var/www/mysite.com/apache> Order allow,deny Allow from all </Directory> Alias / /var/www/mysite.com/apache/php/ <Directory /var/www/mysite.com/apache/php> Options Indexes FollowSymLinks AllowOverride All Order Deny,Allow Allow from all </Directory> ...
This directs each request to the correct handler. However, my Django urls.py looks like this:
... api_patterns = patterns('', url(r'^api/1.0/$', views.api_root), url(r'^api/1.0/oauth/', include('oauth2_provider.urls', namespace='oauth2_provider')), ...
This fails to match any URLs because it is expecting them to begin with api
. This prefix is, of course, being stripped off before it gets here (when the requests arrive here they are in the format 1.0/oauth
etc.).
Is there any way to pass a fully intact URL through to Django?
Solution
Graham Dumpleton, the author of mod_wsgi, suggested a couple of approaches to fix this, both of which worked (see the accepted answer below).
I went for the solution he suggests in UPDATE 1. Appending /api
to the file path solves the problem:
WSGIScriptAlias /api /var/www/mysite.com/apache/django.wsgi/api
i.e. /api
is no longer stripped off the URL by the time it reaches Django.
So here are the relevant parts of my working config:
... DocumentRoot /var/www/mysite.com/apache/php WSGIScriptAlias /api /var/www/mysite.com/apache/service/django.wsgi/api <Directory /var/www/mysite.com/apache/service> WSGIProcessGroup www.mysite.com WSGIPassAuthorization On Options -Indexes Order allow,deny Allow from all </Directory> # PHP web site <Directory /var/www/mysite.com/apache/php> Options -Indexes FollowSymLinks AllowOverride All Order Deny,Allow Allow from all DirectoryIndex index.php </Directory> ...