开发者

setting up two Django websites under Apache with WSGI

开发者 https://www.devze.com 2023-03-14 13:27 出处:网络
I\'ve set up a django website as described in the django docs: https://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/

I've set up a django website as described in the django docs: https://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/

Now I want to setup another version of the site (different source dir, different database) to run on the same serve开发者_如何学JAVAr. There are active users and flex apps who use app #1, so I want to keep app #1 access unchanged. I also rather not change the urls.py at all even for app #2.

I was thinking of different port for app #2

For example

http://192.168.1.1/load_book/123/ will load book from app #1 http://192.168.1.1:444/load_book/123/ will load book from app #2

I'm a complete noob to Apache and WSGI... how do I set it up?


What do you mean by they have the same URLs? The same hostname, perhaps?

Let's say you've got 2 apps:

  • http://example.com/your_app
  • http://example.com/my_app

These can both be Django apps, served by WSGI, on the same Apache instance. Using either Directory or Location directives in your apache conf to specify the .wsgi loader file as described in the django docs linked above:

<Location /your_app>
    WSGIScriptAlias /your_app /path/to/mysite/apache/your_app/django.wsgi
    ...
</Location>
<Location /my_app>
    WSGIScriptAlias /my_app /path/to/mysite/apache/my_app/django.wsgi
    ...
</Location>

The only real gotcha is that you'll need to tell your_app and my_app that they are no longer on the document root of the host. To do this, add a base_url parameter to your settings.py and prefix all of the entries in your urls.py with this param. This will ensure when the request comes through Apache, your python app can route it accordingly.

For an easy example of how this is done, have a look at the code for Bookworm, a Django app.


You can attatch the wsgi application to different sub-paths under the same domain. If you do this the paths to the views inside Django will still be the same. You do not have to modify the urls.py. In the following example Django will regard /site1 as the root of project1.

Check out http://code.google.com/p/modwsgi/wiki/InstallationInstructions for documentation on mod_wsgi.

<VirtualHost *:80>
    ServerName www.example.com

    WSGIDaemonProcess example
    WSGIProcessGroup example
    WSGIScriptAlias /site1 /home/django/project1/deploy/wsgi.py
    <Directory /home/django/project1/deploy>
        Order deny,allow
        Allow from all
    </Directory>

    WSGIScriptAlias /site2 /home/django/project2/deploy/wsgi.py
    <Directory /home/django/project2/deploy>
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

Now the two sites will run in the same daemon process using different python sub-interpreters.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号