First, from Unofficial Windows Binaries for Python Extension Packages, select the wheel file (.whl), which is one of the Python archive formats. to download
There are several types of files, but the ones that are downloaded are
mod_wsgi-[mod_wsgi version]+ap[apache version]vc[Visual Studio compiler version]-cp[Python version]-cp[Python version]m-win[OS bits].whl
Files that match For example, if you try to install in the following environment
mod_wsgi-4.4.23+ap24vc14-cp35-cp35m-win_amd64.whl
Download
Install mod_wsgi using pip
pip install mod_wsgi-4.4.23+ap24vc14-cp35-cp35m-win_amd64.wh
If successful, mod_wsgi.so will be created under the folder where Python is installed.
C:/Program Files/Python35/mod_wsgi.so
Put the created mod_wsgi.so under modules in the folder where Apache is installed.
C:/Programs/Apache24/modules/mod_wsgi.so
Add to httpd.conf
C:/Programs/Apache24/conf/httpd.conf
//Around line 181
LoadModule wsgi_module modules/mod_wsgi.so
In addition, add the following code anywhere
httpd.conf
WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonPath /path/to/mysite.com
<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
If you have the Python modules that your project depends on inside virtualenv, you also need to add the virtualenv site-packages directory to your Python path. To do this, add another line to the Apache configuration
httpd.conf
// X.X is the Python version
WSGIPythonPath /path/to/your/venv/lib/pythonX.X/site-packages
Restart apache
You need wsgi.py in your project to use wsgi_mod You can generate a project containing wsgi.py by executing the following command
django-admin startproject [Project name]
By the way, the contents of wsgi.py are as follows
wsgi.py
"""
WSGI config for helloworld project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "[Project name].settings")
application = get_wsgi_application()
You have now built an Apache + mod_wsgi environment on Windows, but this configuration does not immediately reflect code changes. One way to solve this is to make MaxRequestsPerChild a small number and create an environment where Apache can be restarted easily. For more information, see modwsgi --ReloadingSourceCode.wiki.
httpd.conf
MaxRequestsPerChild 3
Recommended Posts