Django + Apache内部服务器错误:权限被拒绝

时间:2016-06-09 14:55:35

标签: django git apache mod-wsgi

我在我的网站上使用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,
    },
  },
}

1 个答案:

答案 0 :(得分:1)

问题出在文件的settings.py中,控制日志记录的部分。

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

虽然您当然可以使用适当的权限写入/debug.log,但这是一个不太可能的位置。请选择更合适的一个。你可以通过改变这一行来做到这一点:

'filename': 'debug.log',

在您的日志记录设置中。请务必提供完整路径,例如/tmp/debug.log或/var/log/httpd/debug.log

如果你真的想写那个文件吗

 sudo touch /debug.log
 sudo chown www-data:www-data /debug.log

并重新加载mod wsgi