Ubuntu / Django /日志记录/ PermissionError:[Errno 13]权限被拒绝

时间:2019-03-26 18:22:52

标签: django ubuntu-18.04 permission-denied bitnami

Ubuntu 18.04.1 使用Bitnami Django堆栈:bitnami-djangostack-2.1.5-1

启动apache服务时出现此错误:

[16:21:20.028270 2019] [wsgi:error]  Traceback (most recent call last):
[16:21:20.028373 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/python/lib/python3.7/logging/config.py", line 562, in configure
[16:21:20.028395 2019] [wsgi:error]      handler = self.configure_handler(handlers[name])
[16:21:20.028421 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/python/lib/python3.7/logging/config.py", line 735, in configure_handler
[16:21:20.028438 2019] [wsgi:error]      result = factory(**kwargs)
[16:21:20.028463 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/python/lib/python3.7/logging/handlers.py", line 147, in __init__
[16:21:20.028479 2019] [wsgi:error]      BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
[16:21:20.028504 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/python/lib/python3.7/logging/handlers.py", line 54, in __init__
[16:21:20.028520 2019] [wsgi:error]      logging.FileHandler.__init__(self, filename, mode, encoding, delay)
[16:21:20.028545 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/python/lib/python3.7/logging/__init__.py", line 1092, in __init__
[16:21:20.028562 2019] [wsgi:error]      StreamHandler.__init__(self, self._open())
[16:21:20.028601 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/python/lib/python3.7/logging/__init__.py", line 1121, in _open
[16:21:20.028618 2019] [wsgi:error]      return open(self.baseFilename, self.mode, encoding=self.encoding)
[16:21:20.028666 2019] [wsgi:error]  PermissionError: [Errno 13] Permission denied: '/opt/djangostack-2.1.5-1/apps/django/django_projects/myproject/static/logs/ca.myproject.app.cleaner.log'
[16:21:20.028701 2019] [wsgi:error]  
[16:21:20.028716 2019] [wsgi:error]  The above exception was the direct cause of the following exception:
[16:21:20.028729 2019] [wsgi:error]  
[16:21:20.028753 2019] [wsgi:error]  Traceback (most recent call last):
[16:21:20.028832 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/apps/django/django_projects/myproject/myproject/wsgi.py", line 19, in <module>
[16:21:20.028851 2019] [wsgi:error]      application = get_wsgi_application()
[16:21:20.028886 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/apps/django/lib/python3.7/site-packages/Django-2.1.5-py3.7.egg/django/core/wsgi.py", line 12, in get_wsgi_application
[16:21:20.028903 2019] [wsgi:error]      django.setup(set_prefix=False)
[16:21:20.028928 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/apps/django/lib/python3.7/site-packages/Django-2.1.5-py3.7.egg/django/__init__.py", line 19, in setup
[16:21:20.028944 2019] [wsgi:error]      configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[16:21:20.028968 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/apps/django/lib/python3.7/site-packages/Django-2.1.5-py3.7.egg/django/utils/log.py", line 76, in configure_logging
[16:21:20.028984 2019] [wsgi:error]      logging_config_func(logging_settings)
[16:21:20.029008 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/python/lib/python3.7/logging/config.py", line 799, in dictConfig
[16:21:20.029023 2019] [wsgi:error]      dictConfigClass(config).configure()
[16:21:20.029046 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/python/lib/python3.7/logging/config.py", line 570, in configure
[16:21:20.029062 2019] [wsgi:error]      '%r' % name) from e
[16:21:20.029102 2019] [wsgi:error]  ValueError: Unable to configure handler 'cleaner_file'

如何解决?

Django无法在目录/opt/djangostack-2.1.5-1/apps/django/django_projects/myproject/static/logs /

中创建日志文件

在我的项目settings.py中,文件路径被指定为绝对路径,因此Django应该能够将日志文件写入该文件夹。

简短修复: chmod -R 777 $(pwd)/static/logs可以解决此问题,但是重新启动后,错误又回来了:(

感谢您的帮助

0 个答案:

没有答案