apache - wsgi - python - 基本示例

apache - wsgi - python - basic example

所以我被建议使用 wsgi 而不是 cgi,所以我尝试使用以下设置来设置它作为 基本示例 , 没有 Django:

规格:

问题:

真的迷失在这个 wsgi 想法中,一些澄清可能会有所帮助

所以让我们从我知道和想要的开始,使用简约方法:

最有用的信息来自shellhacks.com and modwsgi.readthedocs.io

  • $ sudo apt-get 安装 python3-distutils
  • $ sudo apt-get 安装 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 服务器上设置),您应该会看到所有编程历史中最著名的词,看到这些词感觉很好 :)

要做的事情:创建应用程序,将脚本指向该应用程序,...