<p>我的电脑有Python2.6,所以我将在假设Python2.6是目标版本的情况下使用所有配置。</p>
<ol>
<li>下载最新的xampp(<a href="http://www.apachefriends.org/en/xampp-windows.html" rel="noreferrer">http://www.apachefriends.org/en/xampp-windows.html</a>),截至2010年11月29日,1.7.3版是最新的。</li>
<li>安装xampp for windows,我安装了它c:\ xampp</li>
<li>下载并安装Python2.6(<a href="http://www.python.org/download/releases/2.6/" rel="noreferrer">http://www.python.org/download/releases/2.6/</a>)</li>
<li>下载wsgi for windows-<a href="http://code.google.com/p/modwsgi/wiki/DownloadTheSoftware?tm=2" rel="noreferrer">http://code.google.com/p/modwsgi/wiki/DownloadTheSoftware?tm=2</a>
如有必要,请参阅文档-<a href="http://code.google.com/p/modwsgi/wiki/InstallationOnWindows" rel="noreferrer">http://code.google.com/p/modwsgi/wiki/InstallationOnWindows</a></li>
<li>将so文件复制到模块目录<em>C:\xampp\apache\modules</em>,不要忘记将其重命名为mod wsgi.so</li>
<li>将以下行添加到<em>C:\xampp\apache\conf\httpd.conf</em>
<ul>
<li><strong>加载模块wsgi模块/mod wsgi.so</strong></li>
</ul></li>
<li>使用<em>C:\ xampp\xampp-control.exe</em></li>
</ol>
<p>为了测试我做了以下步骤。</p>
<ol>
<li>创建<em>C:\ xampp\htdocs\wsgi\scripts</em>目录,并复制test test.wsgi。</li>
</ol>
<p>test.wsgi如下所示。</p>
<pre><code>#!/usr/bin/env python
"""
A simple WSGI test application.
Its main purpose is to show that WSGI support works (meaning that the
web server and the WSGI adaptor / support module are configured correctly).
As a nice plus, it outputs some interesting system / WSGI values as a nice
HTML table.
The main use of this script will be using the WSGI "application" defined
below within your production WSGI environment. You will use some code similar
to what you see at the end of this script to use the application from that
environment. For the special case of apache2/mod_wsgi, it shoud be possible
to directly use this file.
If you start this script from the commandline either with python2.5 or with
and older python + wsgiref module installed, it will serve the content on
http://localhost:8000/ - this is mainly for debugging THIS script.
@copyright: 2008 by MoinMoin:ThomasWaldmann
@license: Python License, see LICENSE.Python for details.
"""
import os.path
import os
import sys
try:
__file__
except NameError:
__file__ = '?'
html_template = """\
<html>
<head>
<title>WSGI Test Script</title>
</head>
<body>
<h1>WSGI test script is working!</h1>
<table border=1>
<tr><th colspan=2>1. System Information</th></tr>
<tr><td>Python</td><td>%(python_version)s</td></tr>
<tr><td>Python Path</td><td>%(python_path)s</td></tr>
<tr><td>Platform</td><td>%(platform)s</td></tr>
<tr><td>Absolute path of this script</td><td>%(abs_path)s</td></tr>
<tr><td>Filename</td><td>%(filename)s</td></tr>
<tr><th colspan=2>2. WSGI Environment</th></tr>
%(wsgi_env)s
</table>
</body>
</html>
"""
row_template = " <tr><td>%s</td><td>%r</td></tr>"
def application(environ, start_response):
mysite = '/Users/smcho/Desktop/django'
if mysite not in sys.path:
sys.path.insert(0,'/Users/smcho/Desktop/django')
mysite = '/Users/smcho/Desktop/django/mysite'
if mysite not in sys.path:
sys.path.insert(0,'/Users/smcho/Desktop/django/mysite')
""" The WSGI test application """
# emit status / headers
status = "200 OK"
headers = [('Content-Type', 'text/html'), ]
start_response(status, headers)
# assemble and return content
content = html_template % {
'python_version': sys.version,
'platform': sys.platform,
'abs_path': os.path.abspath('.'),
'filename': __file__,
'python_path': repr(sys.path),
'wsgi_env': '\n'.join([row_template % item for item in environ.items()]),
}
return [content]
if __name__ == '__main__':
# this runs when script is started directly from commandline
try:
# create a simple WSGI server and run the application
from wsgiref import simple_server
print "Running test application - point your browser at http://localhost:8000/ ..."
httpd = simple_server.WSGIServer(('', 8000), simple_server.WSGIRequestHandler)
httpd.set_app(application)
httpd.serve_forever()
except ImportError:
# wsgiref not installed, just output html to stdout
for content in application({}, lambda status, headers: None):
print content
</code></pre>
<ol start=“2”>
<li>使<em>C:\xampp\apache\conf\other\wsgi.conf</em>具有以下内容</li>
</ol>
<p>这是密码</p>
<pre><code><Directory "C:/xampp/htdocs/wsgi/scripts">
Options ExecCGI Indexes
AddHandler cgi-script .cgi
AddHandler wsgi-script .wsgi
Order allow,deny
Allow from all
</Directory>
Alias /wsgi/ "C:/xampp/htdocs/wsgi/scripts/"
<IfModule wsgi_module>
WSGIScriptAlias /test "C:/xampp/htdocs/wsgi/scripts/test.wsgi"
</IfModule>
</code></pre>
<ol start=“3”>
<li>将此行添加到httpd.conf<strong>Include“conf/other/wsgi.conf”</strong></li>
<li>重新启动apache。</li>
<li>当您在web浏览器中输入“localhost/test”或“localost/wsgi/test.wsgi”时,您将看到wsgi信息。</li>
</ol>