Apache WSGI permission error using django logging on production server

假装没事ソ 提交于 2019-12-04 16:44:43

After reading up on SELinux, I have figured out the solution for this permission error. And I hope that it will help the others who have encountered similar situation when deploying on production server under RHEL linux.

Basically running the command ls -Z shows the following

drwxr-xr-x. apache apache unconfined_u:object_r:httpd_sys_content_t:s0 log

the folder is labelled with httpd_sys_content_t which does not allow httpd to have write access the the folder. Therefore we need to change this label to httpd_sys_rw_content_t

Firstly, we need to add an entry to the fcontext to inform SELinux what is the default label for files, that will be created, in this folder.

sudo semanage fcontext -a -t httpd_sys_rw_content_t "/path/to/directory(/.*)?"

This will add an entry to the fcontext file (/etc/selinux/targeted/contexts/files/file_contexts.local)

Next we need to update all the labels of the files in the folder using restorecon.

sudo restorecon -R -v /path/to/directory

And now the permission error related to the django logging will be gone from the httpd error_log =)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!