Django + Apache Internal Server Error: Permission denied

Django + Apache Internal Server Error: Permission denied

我的网站使用 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'

我看到它是 "Permission denied",所以我 运行:

sudo chown -R www-data:www-data mysite

还有:

sudo chmod -R 755 mysite

但是还是不行,我什至把整个html目录的权限改成了777,但是没用。 我不明白为什么会出现权限错误,是否有与我 运行 的 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,
    },
  },
}

问题出在您的 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