2016年7月25日月曜日

wsgi.py で Permission denied が発生した場合の解消方法

mod_wsgi を利用した Django 環境を構築した際、Internal Error が発生した。
エラーログを確認したところ、以下のログが記録されていた。(一部省略)
(13)Permission denied: ...: Call to fopen() failed for '/.../testsite/testsite/wsgi.py'
ディレクトリや wsgi.py に対する permission も問題がないことを確認し、一向に原因がわからなかったが、ここここから、SELinux が原因であることが判明した。

原因を特定するため、ここの記載に従い、まず setroubleshoot-server をインストールした。
sudo yum install setroubleshoot-server
次に該当のサイトへアクセスし、エラーログ(/var/log/messages)を出力させる。
エラーログには、以下のメッセージは出力されていた。
Jul 24 07:46:40 xxxxxx python: SELinux is preventing /usr/sbin/httpd from read access on the directory testsite.

*****  Plugin catchall_boolean (89.3 confidence) suggests   ******************

If you want to allow httpd to read user content
Then you must tell SELinux about this by enabling the 'httpd_read_user_content' boolean.
You can read 'None' man page for more details.
Do
setsebool -P httpd_read_user_content 1


*****  Plugin catchall (11.6 confidence) suggests   **************************

If you believe that httpd should be allowed read access on the testsite directory by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# grep httpd /var/log/audit/audit.log | audit2allow -M mypol
# semodule -i mypol.pp
メッセージに従い、httpd_read_user_content の値を変更(setsebool -P httpd_read_user_content 1)したところ、無事に表示された。

0 件のコメント:

コメントを投稿