---
title: "apache+mod_wsgi配置"
author: "dyna_179"
date: "2010-08-02T23:44:42Z"
tags: ["Apache", "Django", "Google", "Python", "脚本"]
categories: ["编程语言"]
slug: "apache-mod-wsgi"
draft: false
lastmod: "2010-08-02T23:44:42Z"
id: 727620
url: "https://healich.iteye.com/blog/727620"
---

**在apache下配置mod_wsgi**

Apache http Server: <http://httpd.apache.org/>
modwsgi: <http://code.google.com/p/modwsgi/>, <http://code.google.com/p/modwsgi/wiki/InstallationInstructions>
WSGI: <http://www.python.org/dev/peps/pep-0333/>


在安装好apache之后，还需要下载mod_wsgi.mod_wsgi是用于apache支持python wsgi协议的扩展，当前版本是3.3，有windows下支持不同python版本的二进制文件下载。

首先需要使apache httpd服务器加载wsgi_module扩展。将下载的mod_wsgi.so置于apache serverr安装目录的modules文件下，在httpd.conf文件中添加如下一行：

```

LoadModule wsgi_module modules/mod_wsgi.so

```


使用WSGIScriptAlias指令来指定wsgi application的启动脚本。在httpd.conf中添加如下一行，这里使用默认的DocumentRoot:

```

WSGIScriptAlias /test "/path/to/docRoot/test.wsgi"

```

在/test路径下访问测试程序，wsgi脚本文件为test.wsgi


```python

def application(environ, start_response):
    status = '200 OK' 
    output = 'Hello World!'

    response_headers = [('content-type', 'text/plain'),
                        ('content-length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

```


重启apache sever之后，可以通过http://localhost/test来访问测试程序了。如果显示“Hello World!”则表明mod_wsgi安装成功。

**配置apache**
...

**django在apache下的配置**
<http://docs.djangoproject.com/en/1.1/howto/deployment/modwsgi/#howto-deployment-modwsgi>
...