django:mod_wsgi无法在项目目录中打开日志文件

时间:2010-10-27 13:42:26

标签: django mod-wsgi

我正在尝试使用mod_wsgi部署我的项目。不幸的是我得到了:

[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] Exception in WSGI handler: 
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] Traceback (most recent call last):
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/home/project/project/wsgi/project.wsgi", line 26, in application
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     return handler(environ, start_response)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/site-packages/Django-1.2.1-py2.5.egg/django/core/handlers/wsgi.py", line 230, in __call__
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     self.load_middleware()
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/site-packages/Django-1.2.1-py2.5.egg/django/core/handlers/base.py", line 33, in load_middleware
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     for middleware_path in settings.MIDDLEWARE_CLASSES:
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/site-packages/Django-1.2.1-py2.5.egg/django/utils/functional.py", line 276, in __getattr__
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     self._setup()
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/site-packages/Django-1.2.1-py2.5.egg/django/conf/__init__.py", line 40, in _setup
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     self._wrapped = Settings(settings_module)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/site-packages/Django-1.2.1-py2.5.egg/django/conf/__init__.py", line 73, in __init__
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     mod = importlib.import_module(self.SETTINGS_MODULE)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/site-packages/Django-1.2.1-py2.5.egg/django/utils/importlib.py", line 35, in import_module
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     __import__(name)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/home/project/project/__init__.py", line 7, in <module>
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     logging.config.fileConfig(settings.LOG_CONFIG)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/logging/config.py", line 84, in fileConfig
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     handlers = _install_handlers(cp, formatters)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/logging/config.py", line 152, in _install_handlers
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     h = apply(klass, args)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/logging/handlers.py", line 109, in __init__
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     BaseRotatingHandler.__init__(self, filename, mode, encoding)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/logging/handlers.py", line 61, in __init__
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     logging.FileHandler.__init__(self, filename, mode, encoding)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/logging/__init__.py", line 772, in __init__
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     stream = open(filename, mode)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] IOError: [Errno 13] Permission denied: 'project.log'

我在/ etc / apache2 / sites-enabled /:

中有我的项目条目
SetEnv app_settings project.config.production
WSGIDaemonProcess project user=project group=project threads=1 processes=1 home=/home/project/project python-path=/home/project
<VirtualHost *>
        ServerName project.internal
        WSGIScriptAlias / /home/project/project/wsgi/project.wsgi
        WSGIProcessGroup %{GLOBAL}
</VirtualHost>

我的日志应该存储在项目目录中。我调查了一下,就在project.log应该打开之前我运行了os.getcwd(),它返回/。任何人都可以告诉我,我可能错误配置了这种情况吗?

2 个答案:

答案 0 :(得分:1)

这不是一个答案,但我将我的网站设置为仅使用绝对路径名,从settings.py拉入基本路径。您可以在settings.py中使用不是官方Django设置名称的变量,只要您使用ALLCAPS_WITH_UNDERSCORES样式命名它们,就可以导入import settings的那些变量。

IIRC,守护进程一般应该使用绝对路径名。显然,使用相对路径名可能是一个安全漏洞。

答案 1 :(得分:0)

这不是路径,而是权限。

apache用户正在尝试创建该日志文件,因此您应该为该目录授予其写入权限。