Apache HTTP 服务器/mod_wsgi
根据项目网站
- mod_wsgi 的目标是实现一个易于使用的 Apache 模块,它可以托管任何支持 Python WSGI 接口的 Python 应用程序。该模块适用于托管高性能生产网站,以及在网络托管服务上运行的普通自管理个人网站。
mod_wsgi 是一个 Apache HTTP 服务器 模块,它在服务器中嵌入 Python 应用程序,并允许它们通过 Python WSGI 接口进行通信,该接口在 Python PEP 333 中定义。WSGI 是 Python 中生成高质量和高性能 Web 应用程序的方法之一。
WSGI 提供了一种标准方式来轻松地连接不同的 Web 应用程序。一些知名的 Python 应用程序或框架提供 wsgi 以方便部署和嵌入。这意味着您可以将 Django 驱动的博客和项目的 Trac 嵌入到单个 Pylons 应用程序中,该应用程序可以包装它们来处理身份验证等,而无需修改前者。
示例
安装
安装 mod_wsgiAUR,它提供了与所有常见 Python 版本 (3.x) 配合使用的模块。
Apache 配置
如安装过程中所示,将以下行添加到 Apache 的配置文件中
/etc/httpd/conf/httpd.conf
LoadModule wsgi_module modules/mod_wsgi.so
重启 httpd.service
。
检查 Apache 是否正常运行。如果之前的命令没有返回任何内容,则表示 Apache 启动良好。否则,您可以使用 httpd.service
单元状态查看错误。
模块测试
在 Apache 配置文件中添加此行
/etc/httpd/conf/httpd.conf
WSGIScriptAlias /wsgi_app /srv/http/wsgi_app.py
创建一个测试文件
/srv/http/wsgi_app.py
#-*- coding: utf-8 -*- def wsgi_app(environ, start_response): import sys output = sys.version.encode('utf8') status = '200 OK' headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, headers) yield output # mod_wsgi need the *application* variable to serve our small app application = wsgi_app
重启 httpd.service
您可以通过访问以下地址检查是否正常运行:https://127.0.0.1/wsgi_app