事象
CentOS 7にNginxをインストールし、設定ファイルを他からコピーしてくると
systemctl start nginx
実行のタイミングで
error.log
[root@localhost ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since 火 2016-03-08 14:09:21 JST; 11min ago
Process: 3012 ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)
3月 08 14:09:21 localhost.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy server...
3月 08 14:09:21 localhost.localdomain nginx[3012]: nginx: [emerg] open() "/etc/nginx/addtional.conf" failed (13: Permission denied) in /etc/nginx/nginx.conf:52
3月 08 14:09:21 localhost.localdomain nginx[3012]: nginx: configuration file /etc/nginx/nginx.conf test failed
3月 08 14:09:21 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1
3月 08 14:09:21 localhost.localdomain systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
3月 08 14:09:21 localhost.localdomain systemd[1]: Unit nginx.service entered failed state.
3月 08 14:09:21 localhost.localdomain systemd[1]: nginx.service failed.
が発生することがある。
設定ファイルを当該サーバ上で作成せずに、他のサーバからコピーしてくると発生しやすい。
対応内容
CentOS7.1 64bit SELinuxによるアクセス制御 | kakiro-web カキローウェブ を参考にして実施。
chcon -t httpd_config_t /etc/nginx -R
ls -lZ /etc/nginx/addtional.conf
コピーしてきたものがファイルのみだとファイル指定で良いけど、ディレクトリ毎だとディレクトリ指定でchcon /etc/nginx/addtional.conf
しないといけない。