Serving Django apps using mod_wsgi from a site that does not run Django from /

試著忘記壹切 提交于 2019-12-06 02:54:08

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.

Creech

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!