How to configue apache and mode_wsgi for local django development on windows
The team I currently work with has outgrown the django development server for running django applications within our local development environments. The environment itself (server 2008 vm) is a mix of .net applications backed off of IIS7 coupled with several django applications.
We have a need for being able to have our local development environments run all applications concurrently for ease of development and testing. We have decided to move towards a full instance of apache running alongside IIS to m开发者_如何学运维ore closely resemble our production and testing environments (the difference of course being linux / windows for the host of apache).
We have configured mod_wsgi and apache to run locally however it seems that we do not quite have either the python or the django path configured correctly as at runtime our applications are complaining that views do not exist with error's like:
Could not import reporting.views. Error was: DLL load failed: The specified module could not be found.
The django exception location is showing:
Exception Location: C:\Python27\lib\site-packages\django\core\urlresolvers.py in _get_callback, line 132
Therefore we assume it is some sort of path problem but as of yet we have not been able to figure out what is going wrong.
Thanks all.
LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonHome X:\PathToApplication\venv\Scripts
<VirtualHost *:8000>
ServerName applicationdomain
ServerAlias applicationapidomain
SetEnv DJANGO_ENV local
WSGIScriptAlias / X:/PathToApplication/apache/django.wsgi
<Directory X:/PathToApplication/ >
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:8001>
ServerName applicationdomain
SetEnv DJANGO_ENV local
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
SSLCertificateFile "C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\wildcard.crt"
SSLCertificateKeyFile "C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\wildcard.key"
WSGIScriptAlias / X:/PathToApplication/apache/django.wsgi
<Directory X:/PathToApplication/ >
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Your problem has to do with compiled modules and mod_wsgi.
Python from Python.org has an embedded manifest that allows it to load DLL files. When compiling C modules python used to embed the manifest in the compiled modules, however since has started stripping them out by default. The issue here is that mod_wsgi includes it's own python interpreter which does not have that manifest file included.
I think in order to get this to work you need to either compile with MingW, embed a manifest into Apache, or change python to embed a manifest into the modules you are compiling.
http://www.mail-archive.com/modwsgi@googlegroups.com/msg06255.html has a response from someone who was embedding the manifest into apache2.
If my memory serves somewhere around line 680ish of Python27/Lib/distutils/msvc9compiler.py there should be a bit of code that looks like
try:
# Remove references to the Visual C runtime, so they will
# fall through to the Visual C dependency of Python.exe.
# This way, when installed for a restricted user (e.g.
# runtimes are not in WinSxS folder, but in Python's own
# folder), the runtimes do not need to be in every folder
# with .pyd's.
manifest_f = open(manifest_file)
try:
manifest_buf = manifest_f.read()
finally:
manifest_f.close()
pattern = re.compile(
r"""<assemblyIdentity.*?name=("|')Microsoft\.""" \
r"""VC\d{2}\.CRT("|').*?(/>|</assemblyIdentity>)""",
re.DOTALL)
manifest_buf = re.sub(pattern, "", manifest_buf)
pattern = "<dependentAssembly>\s*</dependentAssembly>"
manifest_buf = re.sub(pattern, "", manifest_buf)
manifest_f = open(manifest_file, 'w')
try:
manifest_f.write(manifest_buf)
finally:
manifest_f.close()
except IOError:
pass
removing or commenting this out should stop python from stripping out the manifest file.
精彩评论