【发布时间】:2016-06-09 14:55:34
【问题描述】:
我的网站使用的是 Django 1.6 和 Apache,起初服务器运行良好,我可以成功访问我的网页,但在我运行之后:
git reset --hard HEAD^
在我的 /var/www/html/mysite 存储库中,它在浏览器中显示内部服务器错误,我在错误日志中得到了这个:
[Thu Jun 09 16:28:32 2016] [info] mod_wsgi (pid=15479): Create interpreter 'www.XXX.XXX|'.
[Thu Jun 09 16:28:32 2016] [info] mod_wsgi (pid=15479): Adding '/var/www/html/mysite' to path.
[Thu Jun 09 16:28:32 2016] [info] mod_wsgi (pid=15479): Adding '/usr/local/lib/python2.7/site-packages' to path.
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] mod_wsgi (pid=15479): Exception occurred processing WSGI script '/var/www/html/mysite/mysite/wsgi.py'.
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] Traceback (most recent call last):
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] File "/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] self.load_middleware()
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 44, in load_middleware
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] for middleware_path in settings.MIDDLEWARE_CLASSES:
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] self._setup(name)
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 50, in _setup
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] self._configure_logging()
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 80, in _configure_logging
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] logging_config_func(self.LOGGING)
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] File "/usr/local/lib/python2.7/logging/config.py", line 794, in dictConfig
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] dictConfigClass(config).configure()
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] File "/usr/local/lib/python2.7/logging/config.py", line 576, in configure
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] '%r: %s' % (name, e))
[Thu Jun 09 16:28:32 2016] [error] [client 10.192.76.11] ValueError: Unable to configure handler 'file': [Errno 13] Permission denied: '/debug.log'
我看到它是“权限被拒绝”,所以我运行了:
sudo chown -R www-data:www-data mysite
还有:
sudo chmod -R 755 mysite
但它仍然无法正常工作,我什至将整个777 目录的权限更改为html,但它没有用。
我不明白为什么会出现权限错误,是否与我运行的 git 命令有关?
PS:我在settings.py中根本没有提到/debug.log,我写道:
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': 'debug.log',
},
},
'loggers': {
'django.request': {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True,
},
},
}
【问题讨论】:
-
设置中的
LOG_ROOT是什么样的?我觉得您的应用程序正在尝试访问绝对目录/debug.log,这是您的 linux 机器中的基本目录。如果您的设置在 repo 中被跟踪,请尝试git blame settings.py并查看更改。 -
好吧,看来我没有在settings.py中添加
LOG_ROOT -
不要登录到单独的文件。登录到控制台处理程序并让 mod_wsgi 捕获 Django 日志输出并将其发送到 Apache 错误日志中。这是更好的方法。请参阅stackoverflow.com/questions/37736077/… 简而言之,问题是您不能为日志使用相对路径,因为默认的当前工作目录可以是任何东西,如果根目录不可写。
-
是的,你是对的,我宁愿使用绝对路径
标签: django git apache mod-wsgi