LoginSignup
2
3

More than 5 years have passed since last update.

SELinuxよりNginxの403エラーについて

Posted at

新しくインストールした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になったことがわかると思います。

参考:

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3