前の記事
OCIのOracle LinuxにいれたWebサーバが動かないときの調べ方
困ったこと
なんかWebサーバが動いてない・・・。普通じゃ解決しないとき
SELinuxがまずいかも・・・。
1.SELinuxエラーの確認
SELinuxエラー確認
うまくいかないことを再現してみる
SELinuxエラーログの確認コマンド
[opc@test-server ~]$sudo ausearch -m avc -ts recent
Email option is specified but /usr/lib/sendmail doesn't seem executable.
----
time->Xxx Xxx 99 99:99:99 2099
type=PROCTITLE msg=audit(1786847593.929:133154): proctitle=6E67696E783A20776F726B65722070726F63657373
type=PROCTITLE msg=audit(9999999999.999:999999): proctitle=999999999999999999999999999999999999999999
type=SYSCALL xxxxxx
----
time->Xxx Xxx 99 99:99:99 2099
type=PROCTITLE msg=audit(1786847593.929:133154): proctitle=6E67696E783A20776F726B65722070726F63657373
type=PROCTITLE msg=audit(9999999999.999:999999): proctitle=999999999999999999999999999999999999999999
type=SYSCALL xxxxxx
実行した日時でエラーが出ていれば、SELinuxのせい!
2.SELinux(perl CGI実行権限)エラーの対応
SELinux(perl CGI実行権限)エラーへの対応
nginxエラーログの確認コマンド
[opc@test-server ~]$ sudo cat /var/log/nginx/error.log
Xxx 99 19:39:29 test-server nginx[298349]: nginx: [emerg] require_pv("PerlScript.pm") failed: "Can't locate PerlScript.pm: /etc/nginx/perl/PerlScript.pm: Permission denied at (eval 1) line 1."
Xxx 99 19:39:29 test-server nginx[298349]: nginx: configuration file /etc/nginx/nginx.conf test failed
Xxx 99 19:39:29 test-server systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
PerlScript.pmが実行できないエラー
SELinuxをオフする
[opc@test-server ~]$ sudo setenforce 0
0でSELinuxをオフ
Nginxを起動してみる
[opc@test-server ~]$ sudo systemctl start nginx
起動できた場合、SELinuxの問題
Nginxを停止する
[opc@test-server ~]$ sudo systemctl stop nginx
SELinuxを有効モード(Enforcing)に戻す
[opc@test-server ~]$ sudo setenforce 1
Perlスクリプト用にNginx設定用のコンテキストを適用・永続化
[opc@test-server ~]$ sudo semanage fcontext -a -t httpd_config_t "/etc/nginx/perl(/.*)?"
[opc@test-server ~]$ sudo restorecon -Rv /etc/nginx/perl
Nginxを再起動
[opc@test-server ~]$ sudo systemctl start nginx
3.SELinux(ファイル操作権限)エラーの対応
SELinux(ファイル操作権限)エラーへの対応
nginxエラーログの確認コマンド
[opc@test-server ~]$ sudo ausearch -m avc -ts recent
type=AVC msg=audit(9999999999.999:999999): avc: denied { write } for pid=999999 comm="nginx" name="data.txt" dev="dm-0" ino=16777685 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:httpd_config_t:s0 tclass=file permissive=1
data.txtが書き込みできないエラー
SELinuxをオフする
[opc@test-server ~]$ sudo setenforce 0
0でSELinuxをオフ
Nginxを起動してみる
[opc@test-server ~]$ sudo systemctl start nginx
更新できた場合、SELinuxの問題
Nginxを停止する
[opc@test-server ~]$ sudo systemctl stop nginx
念のためSELinuxをオフする
[opc@test-server ~]$ sudo setenforce 0
0でSELinuxをオフ
更新対象のファイルに更新許可設定を適用・永続化
[opc@test-server ~]$ sudo chcon -t httpd_sys_rw_content_t /etc/nginx/perl/data.txt
※/etc/nginx/perl/data.txtがエラーになっていたファイル
SELinuxを有効モード(Enforcing)に戻す
[opc@test-server ~]$ sudo setenforce 1
Nginxを再起動
[opc@test-server ~]$ sudo systemctl start nginx
最後に
記事の内容はCC BY-SA 4.0(著作者の情報とCCライセンス継承はお願いします。商用利用・改変・再配布は問題なし)です。