所以我被建议使用 wsgi 而不是 cgi,所以我尝试使用以下设置来设置 basic example,没有 Django:
规范:
- Linux Kubuntu、apache 2.4、python 3.5
- apache 正在运行,已安装并启用 mod_wsgi
- 网站文件在 root/var/www/html/,我有这个文件夹的 sudo 权限
- python 3.5路径是usr/bin/env python3
- python 脚本:“index.py,最简单的脚本,已经可以执行了
- python 可执行文件位于 root/var/www/scripts
问题:
如何让这个函数吐出它的结果
这个 wsgi 脚本是怎么回事?我不需要那个,我也不想要任何 wsgi 扩展
- 我需要引入什么 apache 指令来运行脚本
- 那么“应用程序”功能位于何处?
真的迷失在这个 wsgi 的想法中,一些澄清可能会有所帮助
请您参考如下方法:
所以让我们从我知道和想要的开始,使用简约方法:
最有用的信息来自 shellhacks.com和 modwsgi.readthedocs.io
- $ sudo apt-get install python3-distutils
- $ sudo apt-get install apache2-dev
- 从here下载最新的mod-wsgi模块包并提取
- $ ./configure --with-python=/usr/local/bin/python3.5
- $制作
- $ 须藤安装
- $ cd etc/apache2/mods-available/
- $ SUDO_EDITOR=kate sudoedit wsgi.load
LoadModule wsgi_module modules/mod_wsgi.so
$ sudo a2enmod wsgi
$ sudo service apache2 restart
使用您最喜欢的文本编辑器(在本例中为我的 Kate)将以下“spark.py”脚本放入 apache 的文档根文件夹(对我而言为 root/var/www/html)
$ kate /var/www/html/spark.py
def application(environ, start_response): status = '200 OK' output = b'Hello World!\n' response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output]
将 WSGI 脚本别名指令添加到 etc/apache2/sites-available/000-default.conf
$ sudo kate etc/apache2/sites-available/000-default.conf
<VirtualHost *:80> #lots and lots of comments some actual directives like DocumentRoot /var/www/html # more comments more directives # and all the way at the end # THE ACTUAL DIRECTIVE WSGIScriptAlias / /var/www/html/spark.py <Directory /usr/lib/python3.7> Require all granted </Directory> </VirtualHost>
- $ sudo 服务重启apache
- 浏览到本地主机(如果您在本地 apache 服务器上设置),您应该会看到所有编程历史中最著名的词,看到这些词感觉很好 :)
要做的事情:创建应用程序,将脚本指向它,...
