【问题标题】:mod_wsgi python conf parsermod_wsgi python conf解析器
【发布时间】:2012-02-17 11:37:30
【问题描述】:

我用mod_wsgi搭建了apache下的python web微框架flask。

除了 python confparser 之外,该应用程序运行良好。这不会引发错误:

parser = ConfigParser.ConfigParser()
parser.read('snati.con')

但是当我添加:

parser.get('database', 'user')

我得到 internal server error Apache 的 error.log 中没有任何内容

我也试过了:

file = open("sample.txt")

同样的结果。

肯定有一些配置问题,但我找不到。

我的 apache conf 看起来像:

WSGIRestrictStdout Off

<VirtualHost *:80>
    ServerName my.com

    WSGIDaemonProcess myapp user=me group=me threads=5

    WSGIScriptAlias / /home/me/www/myapp.wsgi

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

我的 app.wsgi

#active the python virtualenv for this application
activate_this = '/home/gilles/www/snati/env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))


import sys
sys.path.insert(0, '/home/gilles/www/snati/src')
sys.stdout = sys.stderr

from app import app as application

什么可能是错误的,为什么我在 Apache 日志中看不到错误?

【问题讨论】:

    标签: python mod-wsgi flask


    【解决方案1】:

    在 Python 代码中使用文件的绝对路径,而不是相对路径。

    进程的当前工作目录不会是您的应用程序代码和文件所在的位置。

    您没有看到任何错误,因为如果不在调试模式下,Flask 将不会记录它们。设置应用程序以捕获它们并通过电子邮件发送它们或以其他方式记录它们。我不记得 Flask 对后者有什么选择。

    【讨论】:

    • 我同意那个写 mod_wsgi 的人!
    • 在 if "name"=="main"
    【解决方案2】:

    使用 home 变量添加 apache 设置文件的路径

    WSGIDaemonProcess myapp user=me group=me threads=5 home=/path/to/your/directory
    

    这会改变进程的工作目录。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-31
      • 1970-01-01
      • 2012-06-18
      • 2021-12-14
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      相关资源
      最近更新 更多