2016-06-09 120 views
1

我使用Django 1.6和Apache为我的网站,在第一服务器运作良好,我能够成功去我的网页,但我跑得后:的Django + 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' 

我看到它是“权限不足”,所以我ve run:

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

而且也:

sudo chmod -R 755 mysite 

但它仍然没有工作,我甚至改变了pe​​rsmission到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

什么是设置中的LOG_ROOT?我觉得你的应用程序试图访问绝对目录'/ debug.log',它是你的Linux机器的基本目录。如果您的设置在回购中被跟踪,请尝试'git blame settings.py'并查看更改。 –

+0

好吧,我没有在settings.py –

+0

中添加'LOG_ROOT'不要登录到单独的文件。登录到控制台处理程序并使mod_wsgi捕获Django日志输出并将其发送到Apache错误日志中。这是更好的方式。查看http://stackoverflow.com/questions/37736077/log-all-requests-to-file-django总之,问题是你不能使用相对路径作为日志,因为默认的当前工作目录可能是任何东西,如果root目录不可写。 –

回答

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 

和重装国防部WSGI

+0

我甚至重新启动Apache,但得到了同样的错误 –