2010-10-27 116 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