Apache配置WSGI

Apache配置WSGI

什么是WSGI

WSGI被称作web服务器网关接口,在笔者看来其实是基于CGI标准针对Python语言做了一些改进,其主要功能是规范了web 服务器与Pythonj应用程序之间的交互方式,为Python在web开发方面提供了便利而已。关于WSGI原生开发可以阅读参考部分的第一个链接。本文主要讲解如何配置WSGI,从而使得Apache服务器能够支持Python程序。

操作环境

操作系统:ubuntu 16
Apache服务器:Apache 2.4.18
Python:2.7.12

安装与加载

安装WSGI模块

# sudo apt install libapache2-mod-wsgi

启用WSGI模块

# sudo a2enmod wsgi

配置WSGI

编辑文件/etc/apache2/mods-enabled/wsgi.conf

<IfModule mod_wsgi.c>                                                                                   WSGIScriptAlias /test /var/www/html/test.wsgi          #添加该行
</IfModule>

编写测试脚本

/var/www/html目录下创建test.wsgi文件,在文件中添加以下代码

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]

访问

在浏览器中访问http://地址/test ,可以看到页面上显示“Hello World!”。

参考

WSGI原生开发

Apache配置WSGI

Django在Aapache上的部署

转载于:https://www.cnblogs.com/xidongyu/p/9031290.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值