新しくインストールしたNginxのhtmlフォルダに他箇所に作成したファイルをコーピーし、403になた。
おおむね操作の流れ
# yum install nginx
# cd /tmp
# echo "hello" > result.html
# mv result.html /usr/share/nginx/html/
エラーログ/var/log/nginx/error.log
にこうなっています。
2017/08/21 02:33:21 [error] 10738#0: *5 open() "/usr/share/nginx/html/result.html" failed (13: Permission denied), client: 10.0.2.2, server: _, request: "GET /result.html HTTP/1.1", host: "localhost:8080"
Nginxのユーザはnginx
、それにファイルシステムにちゃんとあってます。
drwxr-xr-x. 2 nginx nginx 4096 Aug 21 02:38 html
パーミッションが正しくなっているのに、ログにPermission denied
が出ったのはおかしいです。
# getenforce
Enforcing
# setenforce Permissive
結果的にはSELinuxのが原因です。
ちょっと調べたら、こういうことです。
# ls -Z
-rw-r--r--. nginx nginx system_u:object_r:httpd_sys_content_t:s0 index.html
-rw-r--r--. nginx nginx unconfined_u:object_r:user_tmp_t:s0 result.html
result.html
ファイルのラベルが明らかに違います。
解決案は、SELinuxを無効にるか、またはrestorecon
などのコマンドよりラベルをリフレッシュするか。
# restorecon result.html
# ls -Z
-rw-r--r--. nginx nginx unconfined_u:object_r:httpd_sys_content_t:s0 result.html
user_tmp_t
からhttpd_sys_content_t
になったことがわかると思います。
参考: