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

发布于 2024-09-29 13:13:16 字数 4082 浏览 1 评论 0原文

我正在尝试使用 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(),它返回了 /。谁能告诉我,我可能配置错误导致发生这种情况?

I am trying to deploy my project using mod_wsgi. Unfortunately I get:

[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'

I have an entry for my project inside /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>

My logs should be stored inside the project directory. I have investigated it a little and just before project.log is supposed to be opened I run os.getcwd(), which returned /. Can anyone tell me, what I might have misconfigured that this happens?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

要走干脆点 2024-10-06 13:13:16

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

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

This is not much of an answer, but I set my site up to only use absolute pathnames, pulling in the base paths from settings.py. You can have variables in settings.py that aren't official Django settings names, and as long as you name them using ALLCAPS_WITH_UNDERSCORES style, it will let you import those with import settings.

IIRC, daemons in general should use absolute pathnames. Apparently, using relative pathnames can be a security hole.

执笔绘流年 2024-10-06 13:13:16

这与路径无关,与权限有关。

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

It's not about paths, it's about permissions.

The apache user is trying to create that log file, so you should give it write permissions on that directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文