Windows + Django + Apache 2.2 and multiple Virtual Hosts

402 views
Skip to first unread message

Steinar Rune Eriksen

unread,
Sep 5, 2009, 4:56:36 AM9/5/09
to modwsgi
I am not able to start multiple hosts on my Windows/Apache/Django.
The second entry crashes Apache with error 500. If I switch my
servers around, it is still always the second one that crashes. Is
this a non workable setup on Windows without multiple daaemon
processes for each application?

Log says:

[Sat Sep 05 09:30:58 2009] [error] Unable to read settings_local.py
[Sat Sep 05 09:30:58 2009] [error] [client 10.0.0.5] mod_wsgi
(pid=6052): Exception occurred processing WSGI script 'C:/path/app2/
apache/django.wsgi'.


NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.domain1.no
WSGIScriptAlias / "/path/app1/apache/django.wsgi"
<Directory "/path/app1/apache">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName www.domain2.no
WSGIScriptAlias / "/path/app2/apache/django.wsgi"
<Directory "/path/app2/apache">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>


My wsgi files are identical

import os, sys
WSGI_ROOT = os.path.normpath(os.path.dirname(__file__))
home = WSGI_ROOT + '/../'
if not home in sys.path:
sys.path.insert(0, home)

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Graham Dumpleton

unread,
Sep 5, 2009, 6:23:52 AM9/5/09
to mod...@googlegroups.com
2009/9/5 Steinar Rune Eriksen <s.r.e...@gmail.com>:

>
> I am not able to start multiple hosts on my Windows/Apache/Django.
> The second entry crashes Apache with error 500.

If you are getting a 500 error response, you aren't actually crashing
Apache, just the requests are failing. The questions is whether it is
a 500 error from Apache/mod_wsgi or from Django.

> If I switch my
> servers around, it is still always the second one that crashes. Is
> this a non workable setup on Windows without multiple daaemon
> processes for each application?

Generally it would work fine. There are some caveats, but doubt very
much that they would be your problem at this point.

> Log says:
>
> [Sat Sep 05 09:30:58 2009] [error] Unable to read settings_local.py
> [Sat Sep 05 09:30:58 2009] [error] [client 10.0.0.5] mod_wsgi
> (pid=6052): Exception occurred processing WSGI script 'C:/path/app2/
> apache/django.wsgi'.

What was the rest of the error log output around that section? There
is likely a Python error traceback and other stuff. Please post
sections from before and after that point. Basically anything onwards
from point you made the request.

> NameVirtualHost *:80
>
> <VirtualHost *:80>
>        ServerName www.domain1.no
>        WSGIScriptAlias / "/path/app1/apache/django.wsgi"
>        <Directory "/path/app1/apache">
>                AllowOverride None
>                Options None
>                Order allow,deny
>                Allow from all
>        </Directory>
> </VirtualHost>
>
> <VirtualHost *:80>
>        ServerName www.domain2.no
>        WSGIScriptAlias / "/path/app2/apache/django.wsgi"
>        <Directory "/path/app2/apache">
>                AllowOverride None
>                Options None
>                Order allow,deny
>                Allow from all
>        </Directory>
> </VirtualHost>
>
>
> My wsgi files are identical
>
> import os, sys
> WSGI_ROOT = os.path.normpath(os.path.dirname(__file__))

You shouldn't need os.path.normpath().

> home = WSGI_ROOT + '/../'

Read up Python documentation about os.path.join().

This is possible wrong anyway, as you generally would use two
directories above the 'apache' subdirectory you created.

> if not home in sys.path:
>    sys.path.insert(0, home)
>
> os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

Always a bad idea to use just settings.

You should set sys.path to be directory containing your Django
instances, not the Django instances themselves. The
DJANGO_SETTINGS_MODULE variable should then reference the site name,
ie., directory the instance is stored in.

> import django.core.handlers.wsgi
> application = django.core.handlers.wsgi.WSGIHandler()

Graham

Steinar Rune Eriksen

unread,
Sep 5, 2009, 7:39:49 AM9/5/09
to modwsgi

Thanks for the feedback. I updated the references to settings from the
directory above the instances themselves, as you suggested. Still got
the same error, and as before only when accessing the second
application in httpd.conf.

[Sat Sep 05 13:17:23 2009] [error] Unable to read settings_local.py
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] mod_wsgi
(pid=600): Exception occurred processing WSGI script 'C:/web/app2/
apache/django.wsgi'.
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] Traceback (most
recent call last):
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] File "C:\
\Programs\\Python26\\lib\\site-packages\\django\\core\\handlers\
\wsgi.py", line 230, in __call__
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5]
self.load_middleware()
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] File "C:\
\Programs\\Python26\\lib\\site-packages\\django\\core\\handlers\
\base.py", line 40, in load_middleware
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] mod =
import_module(mw_module)
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] File "C:\
\Programs\\Python26\\lib\\site-packages\\django\\utils\\importlib.py",
line 35, in import_module
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] __import__
(name)
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] File "c:\\web\
\app2\\./../django-blog-common/apps\\middleware\\dynamicsite.py", line
3, in <module>
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] from
django.contrib.sites.models import Site
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] File "C:\
\Programs\\Python26\\lib\\site-packages\\django\\contrib\\sites\
\models.py", line 1, in <module>
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] from
django.db import models
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] File "C:\
\Programs\\Python26\\lib\\site-packages\\django\\db\\models\
\__init__.py", line 12, in <module>
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] from
django.db.models.fields.files import FileField, ImageField
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] File "C:\
\Programs\\Python26\\lib\\site-packages\\django\\db\\models\\fields\
\files.py", line 8, in <module>
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] from
django.core.files.storage import default_storage
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] File "C:\
\Programs\\Python26\\lib\\site-packages\\django\\core\\files\
\storage.py", line 7, in <module>
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] from
django.core.files import locks, File
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] File "C:\
\Programs\\Python26\\lib\\site-packages\\django\\core\\files\
\locks.py", line 25, in <module>
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] import
pywintypes
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] File "C:\
\Programs\\Python26\\lib\\site-packages\\win32\\lib\\pywintypes.py",
line 124, in <module>
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5]
__import_pywin32_system_module__("pywintypes", globals())
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] File "C:\
\Programs\\Python26\\lib\\site-packages\\win32\\lib\\pywintypes.py",
line 114, in __import_pywin32_system_module__
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] assert
sys.modules[modname] is old_mod
[Sat Sep 05 13:17:24 2009] [error] [client 10.0.0.5] AssertionError

Graham Dumpleton

unread,
Sep 5, 2009, 8:24:54 AM9/5/09
to mod...@googlegroups.com
2009/9/5 Steinar Rune Eriksen <s.r.e...@gmail.com>:
>
>
> Thanks for the feedback. I updated the references to settings from the
> directory above the instances themselves, as you suggested. Still got
> the same error, and as before only when accessing the second
> application in httpd.conf.

If you are saying that each site works fine when loaded alone. Ie.,
alternate been running only one VirtualHost, then I would hazard a
guess and say you are using some C extension module for Python that
hasn't been written correctly so as to be possible to use it from
multiple Python sub interpreters in one process at the same time.

I can't think of what else the problem may be.

So, as long as the module is used, you may be limited to running one
site instance which makes use of it.

Graham

Steinar Rune Eriksen

unread,
Sep 6, 2009, 7:06:24 PM9/6/09
to modwsgi
Just thought I mention that I think I found the problem, or at least a
way around it. You are right in that this must be due to some
extension of some sort, and it seems like it is working on a laptop
where I just discovered that I had pywin32-210.win32 rather than
pywin32-214.win32. The latter was causing the problems. When replacing
on the server it worked there as well.
Reply all
Reply to author
Forward
0 new messages