我想爲我的網站啓用錯誤日誌記錄。所以我在我的項目的根目錄下創建了一個名爲log.txt的文件。django錯誤日誌記錄:[Errno 13]權限被拒絕
/home/xyz/public_html/projectname/log.txt
,並在我這個地址setting.py:
/home/xyz/public_html/projectname/projectname/settings.py
我有一個簡單的日誌記錄設置:
LOGGINGs = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt' : "%d/%b/%Y %H:%M:%S"
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': 'log.txt',
'formatter': 'verbose'
},
},
'loggers': {
'django': {
'handlers':['file'],
'propagate': True,
'level':'DEBUG',
},
}
}
這工作我localhostbut罰款,當我把它放到網上時我試圖啓動我得到的服務器:
[Tue Nov 22 04:27:37.817043 2016] [wsgi:error] [pid 3619] [remote 111.113.21.35:0] ValueError: Unable to configure handler 'file': [Errno 13] Permission denied: '/log.txt'
這裏是錯誤堆棧:
(XID d4tgu5) Database Connect Error: Access denied for user 'leechprotect'@'localhost' (using password: YES)
[Tue Nov 22 04:36:25.934018 2016] [wsgi:info] [pid 4882] mod_wsgi (pid=4882): Create interpreter 'myproject.com|'.
[Tue Nov 22 04:36:25.960785 2016] [wsgi:info] [pid 4882] mod_wsgi (pid=4882): Adding '/home/xyz/public_html/myproject' to path.
[Tue Nov 22 04:36:25.961397 2016] [wsgi:info] [pid 4882] mod_wsgi (pid=4882): Adding '/usr/local/lib/python3.4/site-packages/' to path.
[Tue Nov 22 04:36:25.963133 2016] [wsgi:info] [pid 4882] mod_wsgi (pid=4882, process='myproject', application='myproject.com|'): Loading WSGI script '/home/xyz/public_html/myproject/myproject/wsgi.py'.
[Tue Nov 22 04:36:26.016998 2016] [wsgi:info] [pid 4925] mod_wsgi (pid=4925): Initializing Python.
[Tue Nov 22 04:36:26.049383 2016] [wsgi:info] [pid 4925] mod_wsgi (pid=4925): Attach interpreter ''.
[Tue Nov 22 04:36:26.386166 2016] [wsgi:error] [pid 4882] mod_wsgi (pid=4882): Target WSGI script '/home/xyz/public_html/myproject/myproject/wsgi.py' cannot be loaded as Pytho
n module.
[Tue Nov 22 04:36:26.386312 2016] [wsgi:error] [pid 4882] mod_wsgi (pid=4882): Exception occurred processing WSGI script '/home/xyz/public_html/myproject/myproject/wsgi.py'.
[Tue Nov 22 04:36:26.386413 2016] [wsgi:error] [pid 4882] Traceback (most recent call last):
[Tue Nov 22 04:36:26.387088 2016] [wsgi:error] [pid 4882] File "/usr/local/lib/python3.4/lib/python3.4/logging/config.py", line 557, in configure
[Tue Nov 22 04:36:26.387135 2016] [wsgi:error] [pid 4882] handler = self.configure_handler(handlers[name])
[Tue Nov 22 04:36:26.387239 2016] [wsgi:error] [pid 4882] File "/usr/local/lib/python3.4/lib/python3.4/logging/config.py", line 725, in configure_handler
[Tue Nov 22 04:36:26.387263 2016] [wsgi:error] [pid 4882] result = factory(**kwargs)
[Tue Nov 22 04:36:26.388223 2016] [wsgi:error] [pid 4882] File "/usr/local/lib/python3.4/lib/python3.4/logging/__init__.py", line 1006, in __init__
[Tue Nov 22 04:36:26.388268 2016] [wsgi:error] [pid 4882] StreamHandler.__init__(self, self._open())
[Tue Nov 22 04:36:26.388337 2016] [wsgi:error] [pid 4882] File "/usr/local/lib/python3.4/lib/python3.4/logging/__init__.py", line 1035, in _open
[Tue Nov 22 04:36:26.388360 2016] [wsgi:error] [pid 4882] return open(self.baseFilename, self.mode, encoding=self.encoding)
[Tue Nov 22 04:36:26.388418 2016] [wsgi:error] [pid 4882] PermissionError: [Errno 13] Permission denied: '/log.txt'
[Tue Nov 22 04:36:26.388464 2016] [wsgi:error] [pid 4882]
[Tue Nov 22 04:36:26.388483 2016] [wsgi:error] [pid 4882] During handling of the above exception, another exception occurred:
[Tue Nov 22 04:36:26.388491 2016] [wsgi:error] [pid 4882]
[Tue Nov 22 04:36:26.388509 2016] [wsgi:error] [pid 4882] Traceback (most recent call last):
[Tue Nov 22 04:36:26.388781 2016] [wsgi:error] [pid 4882] File "/home/xyz/public_html/myproject/myproject/wsgi.py", line 16, in <module>
[Tue Nov 22 04:36:26.388819 2016] [wsgi:error] [pid 4882] application = get_wsgi_application()
[Tue Nov 22 04:36:26.389032 2016] [wsgi:error] [pid 4882] File "/usr/local/lib/python3.4/lib/python3.4/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Tue Nov 22 04:36:26.389064 2016] [wsgi:error] [pid 4882] django.setup()
[Tue Nov 22 04:36:26.389245 2016] [wsgi:error] [pid 4882] File "/usr/local/lib/python3.4/lib/python3.4/site-packages/django/__init__.py", line 17, in setup
[Tue Nov 22 04:36:26.389273 2016] [wsgi:error] [pid 4882] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Tue Nov 22 04:36:26.389521 2016] [wsgi:error] [pid 4882] File "/usr/local/lib/python3.4/lib/python3.4/site-packages/django/utils/log.py", line 71, in configure_logging
[Tue Nov 22 04:36:26.389590 2016] [wsgi:error] [pid 4882] logging_config_func(logging_settings)
[Tue Nov 22 04:36:26.389657 2016] [wsgi:error] [pid 4882] File "/usr/local/lib/python3.4/lib/python3.4/logging/config.py", line 789, in dictConfig
[Tue Nov 22 04:36:26.389680 2016] [wsgi:error] [pid 4882] dictConfigClass(config).configure()
[Tue Nov 22 04:36:26.389726 2016] [wsgi:error] [pid 4882] File "/usr/local/lib/python3.4/lib/python3.4/logging/config.py", line 565, in configure
[Tue Nov 22 04:36:26.389745 2016] [wsgi:error] [pid 4882] '%r: %s' % (name, e))
[Tue Nov 22 04:36:26.389784 2016] [wsgi:error] [pid 4882] ValueError: Unable to configure handler 'file': [Errno 13] Permission denied: '/log.txt'
[Tue Nov 22 04:36:26.390725 2016] [wsgi:info] [pid 4882] mod_wsgi (pid=4882, process='myproject', application='myproject.com|'): Loading WSGI script '/home/xyz/public_html/neg
inpay/myproject/wsgi.py'.
[Tue Nov 22 04:36:26.392489 2016] [wsgi:error] [pid 4882] mod_wsgi (pid=4882): Target WSGI script '/home/xyz/public_html/myproject/myproject/wsgi.py' cannot be loaded as Pytho
n module.
[Tue Nov 22 04:36:26.392630 2016] [wsgi:error] [pid 4882] mod_wsgi (pid=4882): Exception occurred processing WSGI script '/home/xyz/public_html/myproject/myproject/wsgi.py'.
[Tue Nov 22 04:36:26.392724 2016] [wsgi:error] [pid 4882] Traceback (most recent call last):
[Tue Nov 22 04:36:26.392821 2016] [wsgi:error] [pid 4882] File "/usr/local/lib/python3.4/lib/python3.4/logging/config.py", line 557, in configure
[Tue Nov 22 04:36:26.392835 2016] [wsgi:error] [pid 4882] handler = self.configure_handler(handlers[name])
[Tue Nov 22 04:36:26.392882 2016] [wsgi:error] [pid 4882] File "/usr/local/lib/python3.4/lib/python3.4/logging/config.py", line 725, in configure_handler
[Tue Nov 22 04:36:26.392892 2016] [wsgi:error] [pid 4882] result = factory(**kwargs)
[Tue Nov 22 04:36:26.392931 2016] [wsgi:error] [pid 4882] File "/usr/local/lib/python3.4/lib/python3.4/logging/__init__.py", line 1006, in __init__
[Tue Nov 22 04:36:26.392941 2016] [wsgi:error] [pid 4882] StreamHandler.__init__(self, self._open())
[Tue Nov 22 04:36:26.392976 2016] [wsgi:error] [pid 4882] File "/usr/local/lib/python3.4/lib/python3.4/logging/__init__.py", line 1035, in _open
[Tue Nov 22 04:36:26.392985 2016] [wsgi:error] [pid 4882] return open(self.baseFilename, self.mode, encoding=self.encoding)
[Tue Nov 22 04:36:26.393021 2016] [wsgi:error] [pid 4882] PermissionError: [Errno 13] Permission denied: '/log.txt'
因此,我認爲它是如此我暫時將其設置爲777,直到我找到一個更好的解決方案日誌文件的權限。現在我有:
ls -l /home/xyz/public_html/myproject/log.txt
-rwxrwxrwx. 1 xyz xyz 0 Nov 22 03:19 /home/xyz/public_html/myproject/log.txt
它沒有工作,然後我搜索了一下,發現一些有這個問題,因爲SELinux。所以我已經變成其關閉,以及我現在有:
[[email protected]]# sestatus
SELinux status: disabled
但仍沒有運氣,我得到這個錯誤
這實際上是因爲Apache從系統啓動腳本啓動並繼承'/'作爲工作目錄。記錄在http://modwsgi.readthedocs.io/en/develop/user-guides/application-issues.html#application-working-directory –