Window + Apache + WSGI 配置

本文地址:http://blog.csdn.net/spch2008/article/details/8995529


1. 下载并安装Apache HTTP Server 2.2

    我的安装路径:D:\Program Files (x86)\Apache Software Foundation\Apache2.2

    Window + Apache + WSGI 配置_第1张图片


 2. 下载并配置mod_wsgi

      mod_wsgi : http://code.google.com/p/modwsgi/downloads/detail?name=mod_wsgi-win32-ap22py27-3.3.so

      将其改名为mod_wsgi.so,放置到:D:\Program Files (x86)\Apache Software Foundation\Apache2.2\modules


 3. 配置Aapache识别mod_wsgi

     定位到配置文件:D:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf

    添加:LoadModule wsgi_module modules/mod_wsgi.so

    Window + Apache + WSGI 配置_第2张图片


   4. 关联wsgi程序目录

       在C盘创建文件夹(wsgi_app),如:C:\wsgi_app

       配置Apache识别此目录:D:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf       

       添加下面内容。

           WSGIScriptAlias /wsgi "C:/wsgi_app/wsgi_handler.py"

           <Directory "C:/wsgi_app">
                   Options None
                   AllowOverride None
                   Order deny,allow
                   Allow from all
           </Directory>


                  如下图所示:

          Window + Apache + WSGI 配置_第3张图片

        重启Apache

       

5. 配置python

    安装python2.7 - 3.2任一版本,配置环境变量

    假定Python安装在C:\python32文件夹下,则在Path中添加

    C:\python32\;C:\python32\Lib\site-packages\;C:\python32\Scripts\;

  

    打开cmd,输入python

    Window + Apache + WSGI 配置_第4张图片

     显示上述信息,则表示配置成功。


6. 创建wsgi程序

    在C:\wsgi_app中创建wsgi_handler.py

   

def application(environ, start_response):

    response_body = ['Hello World!']

    content_length = 0
    for s in response_body:
        content_length += len(s)
   
    status = '200 OK'
    response_headers = [('Content-Type', 'text/plain'),
                        ('Content-Length', str(content_length))]
    start_response(status, response_headers)

    return response_body

7. 打开浏览器,输入 http://localhost/wsgi

   



附录:当然,也可以直接将程序拷贝到eclipse中去运行,而不需要配置Apache

 

'''
Created on 2013-5-30

@author spch2008
'''

from wsgiref.simple_server import make_server

def application(environ, start_response):

    response_body = ['Hello World!']

    content_length = 0
    for s in response_body:
        content_length += len(s)
   
    status = '200 OK'
    response_headers = [('Content-Type', 'text/plain'),
                        ('Content-Length', str(content_length))]
    start_response(status, response_headers)

    return response_body
   
httpd = make_server('localhost', 8080, application)
httpd.serve_forever()

打开浏览器,输入 http://localhost:8080/



你可能感兴趣的:(Window + Apache + WSGI 配置)