使用mod_wsgi运行wsgi应用程序失败了

时间:2012-03-24 21:46:36

标签: python apache mod-wsgi openshift

为了调试一个bottle.py应用程序,我正在尝试部署到openshift(有一个问题,我怀疑是连接到mod_wsgi - 这个open question)我正在尝试在我的linux工作站上运行mod_wsgi。正如标题所述 - 我惨遭失败。

我根据mod_wsgi wiki中的说明下载并安装了编译到python2.6的mod_wsgi。

运行apache2ctl -M我确认mod_wsgi(共享)在结果列表中,所以我想我已经有了那个部分

我在/ etc / apache2 / sites-availble中写了 appname 文件,其中包含:

<VirtualHost *:8051> #also tried with * or *:80 or myappname
#   ServerName 127.0.0.1:8051 #also tried to uncomment
    ServerAlias wikimen #also tried without

#   WSGIDaemonProcess wikimen user=myusername group=myusername threads=5 #also tried to uncomment
   WSGIScriptAlias / /home/myusername/workspace/myapp/wsgi/application
   DocumentRoot /home/myusername/workspace/myapp/wsgi

    <Directory /home/myusername/workspace/myapp/wsgi>

#        WSGIProcessGroup myapp
#       WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

并且在跑完之后:

sudo a2ensite

检查它是否已在启用网站的目录中相应地创建并运行:

sudo service apacha2 reload

当我访问浏览器并尝试: localhost:8051或localhost / appname / routename或localhost:8051 / routename或localhost:8051 / appname或它们之间的任何其他组合我刚刚获得(当将localhost更改为127.0.0.1时):

unable to connect

wsgi句柄文件(名为“application”)包含:

#!/usr/bin/python

import os
here = os.path.dirname(os.path.abspath(__file__))


try:

    os.environ['PYTHON_EGG_CACHE'] = os.path.join(os.environ['OPENSHIFT_APP_DIR'],'virtenv/lib/python2.6/site-packages')

except:
    os.environ['PYTHON_EGG_CACHE'] = os.path.join(here,'..','data/virtenv/lib/python2.6/site-packages')

print ('python egg cache set to: %s' % os.environ['PYTHON_EGG_CACHE'])
try:

    virtualenv = os.path.join(os.environ['OPENSHIFT_APP_DIR'],"virtenv/bin/activate_this.py")
except:
    virtualenv = os.path.join(here,'..',"data/virtenv/bin/activate_this.py")

print ('virtualenv is in:%s' % virtualenv)
try:
    execfile(virtualenv, dict(__file__=virtualenv))
    print ('executed')

except IOError:
    pass

from myappname import application

但正如我所说它在openshift服务器中工作(也调用了一些奇怪的bottle.py错误),所以我想这不是问题,我也很乐意被反驳

也许我应该提一下,作为应用程序其余部分的wsgi“application”文件位于virtualenv目录中

我对apache不是很好(我们的生产服务器是使用反向代理和本机python服务器而不是mod_wsgi的切诺基)所以也许我错过了一些基本的东西

如果我直接运行wsgi句柄,则运行基本的bottle.py 我会很高兴得到任何帮助

使用:ubunto 11,apache2.2,当前的mod_wsgi版本,python 2.6(我也有python 2.7,但app根据openshift服务器运行在python2.6的virtualenv中)

拖尾apache2错误日志没有显示任何有用的东西(也杀死它并重新开始):

> [Sat Mar 24 15:45:10 2012] [notice] Apache/2.2.20 (Ubuntu)
> PHP/5.3.6-13ubuntu3.6 with Suhosin-Patch mod_wsgi/3.3 Python/2.6.7
> configured -- resuming normal operations [Sat Mar 24 21:19:24 2012]
> [notice] caught SIGTERM, shutting down [Sat Mar 24 21:19:54 2012]
> [notice] Apache/2.2.20 (Ubuntu) PHP/5.3.6-13ubuntu3.6 with
> Suhosin-Patch mod_wsgi/3.3 Python/2.6.7 configured -- resuming normal
> operations [Sat Mar 24 21:36:30 2012] [notice] Apache/2.2.20 (Ubuntu)
> PHP/5.3.6-13ubuntu3.6 with Suhosin-Patch mod_wsgi/3.3 Python/2.6.7
> configured -- resuming normal operations [Sat Mar 24 21:40:48 2012]
> [notice] caught SIGTERM, shutting down [Sat Mar 24 21:41:18 2012]
> [notice] Apache/2.2.20 (Ubuntu) PHP/5.3.6-13ubuntu3.6 with
> Suhosin-Patch mod_wsgi/3.3 Python/2.6.7 configured -- resuming normal
> operations [Sat Mar 24 23:47:11 2012] [notice] Apache/2.2.20 (Ubuntu)
> PHP/5.3.6-13ubuntu3.6 with Suhosin-Patch mod_wsgi/3.3 Python/2.6.7
> configured -- resuming normal operations [Sun Mar 25 22:20:22 2012]
> [notice] Apache/2.2.20 (Ubuntu) PHP/5.3.6-13ubuntu3.6 with
> Suhosin-Patch mod_wsgi/3.3 Python/2.6.7 configured -- resuming normal
> operations [Sun Mar 25 22:34:12 2012] [notice] caught SIGTERM,
> shutting down [Sun Mar 25 22:34:24 2012] [notice] Apache/2.2.20
> (Ubuntu) PHP/5.3.6-13ubuntu3.6 with Suhosin-Patch mod_wsgi/3.3
> Python/2.6.7 configured -- resuming normal operations

1 个答案:

答案 0 :(得分:1)

我在浏览器中“无法连接”然后与mod_wsgi无关,而是您的浏览器甚至无法连接到服务器。使用您在Apache错误日志中找到的任何错误消息修改您的问题?由于配置文件错误,您的Apache可能无法启动。