2010-10-27 112 views
0

我想用mod_wsgi部署我的项目。不幸的是,我得到:django: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//:

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(),它返回/。任何人都可以告诉我,我可能错误地配置了这种情况?

+0

查看'sys.argv [0]'。 – 2010-10-27 13:50:25

+0

你可以发布你的'project.wsgi'吗? – 2010-10-27 23:03:20

回答

1

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

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

+0

在日志记录配置中使用绝对路径工作(由python日志记录系统使用),但我非常确定,相对路径也可以使用 - 在其他服务器上,我们有django以这种方式部署。我想这样做。 – gruszczy 2010-10-27 19:02:01

+0

然后,你可能需要在你的'project.wsgi'文件中做一个'os.chdir()';也许'os.​​chdir(os.path.dirname(sys.argv [0]))'?关键点是相对路径是* fragile *;你可以通过执行'/ home/project/project/wsgi/project.wsgi'来运行你的程序。那么真的可以保证工作目录总是一样吗? – 2010-10-27 23:02:44

0

这不是路径,而是关于权限。

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

+0

...以及树中向上的所有父目录 – ducu 2011-02-16 13:35:39