apache+mod_wsgi+django配置

在不完全明白之前,看别人的帖子总是觉得是错的,等到弄懂以后,怎么看都是对的。

正题:

安装mod_wsgi,然后记得在http.conf文件里面添加以下一行:
LoadModule wsgi_module modules/mod_wsgi.so

此时的apache就是wsgi服务器了。也许有人会问什么是wsgi服务器。 

# -*- coding: utf-8 -*-
from wsgiref import simple_server
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]

# 下面两行就是简单的wsgi服务器
server = simple_server.make_server('localhost', 8080, application)
server.serve_forever()

注意这行:
server = simple_server.make_server('localhost', 8080, application)
的参数application。这在apache里肯定无法编译进去,所以需要你在你的虚拟主机配置文件的
WSGIScriptAlias / /path/to/your/main.wsgi
行指出,而文件/path/to/your/main.wsgi的内容可能如下:
def application(environ, start_response):  
    status = '200 OK'  
    output = '<h1>Hello World!</h1>'  
   
    response_headers = [('Content-type', 'text/plain'),  
                        ('Content-Length', str(len(output)))]  
    start_response(status, response_headers)  
   
    return [output]
或者
WSGIScriptAlias / /path/to/your/site/wsgi.py
然后wsgi.py就是django自动生成的文件。

转载于:https://my.oschina.net/rst/blog/127314

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值