当前位置: 首页>>技术教程>>正文


如何在Ubuntu上为Python设置Mod_WSGI

, , ,

问题描述

我正在尝试在Ubuntu机器上设置MOD_WSGI。我发现步骤说我需要执行以下在http://ubuntuforums.org/showthread.php?t=833766处发现的步骤

  1. sudo apt-get安装libapache2-mod-wsgi

  2. 须藤a2enmod mod-wsgi

  3. sudo /etc/init.d/apache2重新启动

  4. sudo gedit /etc /apache2 /sites-available /default并更新目录

<Directory /var/www/>   Options Indexes FollowSymLinks MultiViews ExecCGI    AddHandler cgi-script .cgi   AddHandler wsgi-script .wsgi    AllowOverride None   Order allow,deny   allow from all </Directory> 
  1. sudo /etc/init.d/apache2重新启动

  2. 使用创建了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]
    

步骤2失败,因为它说即使apt-get找到了它也找不到mod-wsgi。如果我继续执行这些步骤,则python应用程序仅在浏览器中显示为纯文本。

有任何想法我做错了吗?


编辑:询问问题的结果

automatedtester@ubuntu:~$ dpkg -l libapache2-mod-wsgi
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                   Version                                Description
+++-======================================-======================================-============================================================================================
ii  libapache2-mod-wsgi                    2.5-1                                  Python WSGI adapter module for Apache
automatedtester@ubuntu:~$ dpkg -s libapache2-mod-wsgi
Package: libapache2-mod-wsgi
Status: install ok installed
Priority: optional
Section: python
Installed-Size: 376
Maintainer: Ubuntu MOTU Developers <ubuntu-motu@lists.ubuntu.com>
Architecture: i386
Source: mod-wsgi
Version: 2.5-1
Depends: apache2, apache2.2-common, libc6 (>= 2.4), libpython2.6 (>= 2.6), python (>= 2.5), python (<< 2.7)
Suggests: apache2-mpm-worker | apache2-mpm-event
Conffiles:
 /etc/apache2/mods-available/wsgi.load 06d2b4d2c95b28720f324bd650b7cbd6
 /etc/apache2/mods-available/wsgi.conf 408487581dfe024e8475d2fbf993a15c
Description: Python WSGI adapter module for Apache
 The mod_wsgi adapter is an Apache module that provides a WSGI (Web Server
 Gateway Interface, a standard interface between web server software and
 web applications written in Python) compliant interface for hosting Python
 based web applications within Apache. The adapter provides significantly
 better performance than using existing WSGI adapters for mod_python or CGI.
Original-Maintainer: Debian Python Modules Team <python-modules-team@lists.alioth.debian.org>
Homepage: http://www.modwsgi.org/
automatedtester@ubuntu:~$ sudo a2enmod libapache2-mod-wsgi
ERROR: Module libapache2-mod-wsgi does not exist!
automatedtester@ubuntu:~$ sudo a2enmod mod-wsgi
ERROR: Module mod-wsgi does not exist!

对RMYates的进一步编辑

automatedtester@ubuntu:~$ apache2ctl -t -D DUMP_MODULES
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
Loaded Modules:
 core_module (static)
 log_config_module (static)
 logio_module (static)
 mpm_worker_module (static)
 http_module (static)
 so_module (static)
 alias_module (shared)
 auth_basic_module (shared)
 authn_file_module (shared)
 authz_default_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cgid_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 mime_module (shared)
 negotiation_module (shared)
 python_module (shared)
 setenvif_module (shared)
 status_module (shared)
Syntax OK
automatedtester@ubuntu:~$ 

最佳回答

我发现这是一个已经使用了一年多的mod_wsgi apt-get软件包的已知错误!详细信息位于http://www.mail-archive.com/ubuntu-bugs@lists.ubuntu.com/msg1147225.html。 apt-get软件包没有wsgi.load文件,因此需要通过执行上面的链接中的步骤来创建。

谢谢大家的帮助!

次佳回答

查看模块是否实际通过以下方式正确加载:

apache2ctl -t -D DUMP_MODULES

第三种回答

据我所知,您尚未将mod_wsgi模块加载到httpd.conf中。

我首先尝试将wsgi文件添加到Apache的mods-enabled目录中。

sudo ln -s /etc/apache2/mods-available/wsgi.load /etc/apache2/mods-enabled
sudo ln -s /etc/apache2/mods-available/wsgi.conf /etc/apache2/mods-enabled

然后重新启动Apache,它应该可以工作。

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/10264.html,未经允许,请勿转载。