Multiple django sites under single virtual host

95 views
Skip to first unread message

Shilpa Gaikwad

unread,
Mar 20, 2015, 6:07:41 AM3/20/15
to mod...@googlegroups.com
Hi,

   I want to serve multiple django sites from single virtual host. I am using Apache2.4, mod_wsgi3.5 and windows OS. When I browse sites, first site works but 2nd site does not work. Also I cannot use WSGIProcessDaemon as I am using windows. Please let me know if there is any alternate solution for this.

Graham Dumpleton

unread,
Mar 20, 2015, 6:11:05 AM3/20/15
to mod...@googlegroups.com

On 20/03/2015, at 9:06 PM, Shilpa Gaikwad <shilpa....@gmail.com> wrote:

> Hi,
>
> I want to serve multiple django sites from single virtual host. I am using Apache2.4, mod_wsgi3.5 and windows OS. When I browse sites, first site works but 2nd site does not work. Also I cannot use WSGIProcessDaemon as I am using windows. Please let me know if there is any alternate solution for this.

Define 'does not work'? Do you get an error in the browser, in the Apache error log?

What is the mod_wsgi configuration you are using in the Apache configuration?

What do you have in the wsgi.py file that Django generated for you and which you would have WSGIScriptAlias referring to?

Also ensure you read:

http://blog.dscpl.com.au/2012/10/requests-running-in-wrong-django.html

The generated Django wsgi.py is broken by default when it comes to trying to serve multiple Django applications in sub interpreters of the same process. You need to change how DJANGO_SETTINGS_MODULE is configured.

Graham

Shilpa Gaikwad

unread,
Mar 23, 2015, 3:24:01 AM3/23/15
to mod...@googlegroups.com
For 2nd site it gives 404 error. mod_wsgi version is 3.5. I don't get any error in Apache.
DJANGO_SETTINGS_MODULE is configured as following:

os.environ['DJANGO_SETTINGS_MODULE'] = "reviewboard.settings"

Following is my WSGI configuration in Apache

modwsgi conf for trial site:

    DocumentRoot "E:/rbsites/trial/htdocs"

    # Error handlers
    ErrorDocument 500 E:/rbsites/trial/rb2/htdocs/errordocs/500.html
    
    WSGIPassAuthorization On
    WSGIScriptAlias "/trial/reviewboard" "E:/rbsites/trial/htdocs/reviewboard.wsgi/trial/reviewboard"
    WSGIPythonPath E:/rbsites/trial;D:/virtual_envs/reviewboard_2_0_13/Lib/site-packages
    <Directory "E:/rbsites/trial/htdocs">
        AllowOverride All
        Options -Indexes +FollowSymLinks
        Allow from all
    </Directory>

    # Prevent the server from processing or allowing the rendering of
    # certain file types.
    <Location "/trial/reviewboard/media/uploaded">
        SetHandler None
        Options None

        AddType text/plain .html .htm .shtml .php .php3 .php4 .php5 .phps .asp
        AddType text/plain .pl .py .fcgi .cgi .phtml .phtm .pht .jsp .sh .rb

        <IfModule mod_php5.c>
            php_flag engine off
        </IfModule>
    </Location>

    # Alias static media requests to filesystem
    Alias /trial/reviewboard/media "E:/rbsites/trial/htdocs/media"
    Alias /trial/reviewboard/static "E:/rbsites/trial/htdocs/static"
    Alias /trial/reviewboard/errordocs "E:/rbsites/trial/htdocs/errordocs"
    Alias /trial/reviewboard/favicon.ico "E:/rbsites/trial/htdocs/static/rb/images/favicon.png"

modwsgi conf for testvenv site:


    DocumentRoot "E:/rbsites/rbsite_venev/htdocs"

    # Error handlers
    ErrorDocument 500 E:/rbsites/trial/rb2/htdocs/errordocs/500.html

    WSGIPassAuthorization On
    WSGIScriptAlias "/testvenv" "E:/rbsites/rbsite_venev/htdocs/reviewboard.wsgi/testvenv"
    WSGIPythonPath E:/rbsites/rbsite_venev;D:/virtual_envs/reviewboard_2_0_13/Lib/site-packages
    <Directory "E:/rbsites/rbsite_venev/htdocs">
        AllowOverride All
        Options -Indexes +FollowSymLinks
        Allow from all
    </Directory>

    # Prevent the server from processing or allowing the rendering of
    # certain file types.
    <Location "/testvenv/media/uploaded">
        SetHandler None
        Options None

        AddType text/plain .html .htm .shtml .php .php3 .php4 .php5 .phps .asp
        AddType text/plain .pl .py .fcgi .cgi .phtml .phtm .pht .jsp .sh .rb

        <IfModule mod_php5.c>
            php_flag engine off
        </IfModule>
    </Location>

    # Alias static media requests to filesystem
    Alias /testvenv/media "E:/rbsites/rbsite_venev/htdocs/media"
    Alias /testvenv/static "E:/rbsites/rbsite_venev/htdocs/static"
    Alias /testvenv/errordocs "E:/rbsites/rbsite_venev/htdocs/errordocs"
    Alias /testvenv/favicon.ico "E:/rbsites/rbsite_venev/htdocs/static/rb/images/favicon.png"

Graham Dumpleton

unread,
Mar 23, 2015, 3:33:25 AM3/23/15
to mod...@googlegroups.com
As you are using WSGIPythonPath, that suggests these sites both exist at the top level of Apache, yet they conflict in vary ways. Problems are multiple DocumentRoot and WSGIPythonPath directives. Even fi you have these defined in separate files included into the main Apache configuration, files provide no way to separate them and so the latter will override parts of the former.

Your WSGIScriptAlias directive also looks highly suspicious because it doesn't look to refer to a file, but a directory.

What URL would you be using to access the site?

Graham

--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To post to this group, send email to mod...@googlegroups.com.
Visit this group at http://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Shilpa Gaikwad

unread,
Mar 23, 2015, 6:33:25 AM3/23/15
to mod...@googlegroups.com

Graham Dumpleton

unread,
Mar 23, 2015, 6:48:50 AM3/23/15
to mod...@googlegroups.com
Please don't chop out the preceding conversation, makes it hard to go back and copy and paste to refer to things.

So what I missed is that you are using trick of:

WSGIScriptAlias "/trial/reviewboard" "E:/rbsites/trial/htdocs/reviewboard.wsgi/trial/reviewboard"

whereby you include the mount point after the WSGI script file.

This is quite special and not generally used. What it does is trick the Django site, even though mounted at a sub URL, to think it is mounted at the root of the web site.

Anyway, the issue is still conflicts in the Apache configuration. In particular with WSGIPythonPath.

Only the last WSGIPythonPath will win, overriding the first.

You should not use WSGIPythonPath and instead add the directories inside of the WSGI script file. The site-packages one has to be treated in a special way.

So in E:/rbsites/trial/htdocs/reviewboard.wsgi you would have something like:

import sys

sys.path.insert(0, 'E:/rbsites/trial')

activate_this = 'D:/virtual_envs/reviewboard_2_0_13/Bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

You will need to find where that activate_this.py file is as I don't know exactly which directory it will be in for Windows.

For your other WSGI script file you would use whatever paths is appropriate for it.

So get rid of WSGIPythonPath and add path in WSGI script file and activate virtual environment in there as well.

Details of virtual environment activation can be found in:


Graham

http://servername/trial/reviewboard

Reply all
Reply to author
Forward
0 new messages