SystemDで実行するとnginxが表示されない

SystemDで実行するとnginxが表示されない

次のコマンドを使用してメインラインnginx 1.13.9をインストールしました。提供速度CentOS 7.4で。yum localinstallコーポレートガバナンスがそうすることを強制するので、このrpmを使用する必要があります。

私の問題は、systemctl start nginx常に次のような結果が出てくることです。

Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

Journalctlは次のように言います。

Mar 07 08:57:05 myhost nginx[19466]: nginx: [emerg] open() "/var/opt/nginx/config/nginx.conf" failed (13: Permission denied)

(ここで見ることができるのは別の会社のことです。confファイルを背中に置くことはできず、変更するためにroot権限を必要としないディレクトリに保管する必要があります)

nginx.confに設定された権限は次のとおりです。

-rw-r--r--. 1 nginx nginx 241 Mar 7 09:17 nginx.conf

私はnginx.confを絶対最小値に減らし、ログファイル、pidなどを権限のあるディレクトリに入れました。エラーログには何も含まれていません。

以下は縮小されたnginx.confです。

user nginx nginx;
pid /tmp/nginx.pid;
error_log /tmp/error.log debug;

events {
}

http {
  default_type application/octet-stream;
  charset      UTF-8;

  server {
    listen          8080;
    location / {
      root /tmp/;
    }
  }
}

わずかに変更されたnginx.service定義は次のとおりです。

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStart=/usr/sbin/nginx -c /var/opt/nginx/config/nginx.conf -g "error_log  /tmp/error.log debug;"
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

(nginx.confを読む前にnginxが失敗した場合に備えて、error_logを強制しようとしていることがわかります)

これは本当に効果的ですsudo -u nginx /usr/sbin/nginx -c /var/opt/nginx/config/nginx.conf -g "error_log /tmp/error.log debug;"。単純な警告にもかかわらず、プロセスは正常に開始されます。

nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /var/opt/nginx/config/nginx.conf:1

私はこれが愚かな間違いであるに違いないと確信していますが、どのような間違いなのかはわかりません。

ベストアンサー1

この問題は、私が犯した2つの間違いによって引き起こされました。

  • ディレクトリ権限が正しくありません。
  • グループメンバーシップがありません。

ディレクトリの1つが欠落しているため、プロセスはxパスを通過できません。私はchmod g+Xそれをしなければならなかった。これに加えて、nginxグループにnginx技術ユーザー(私のシナリオではデフォルトのnginxではない)を追加する必要がありました。

おすすめ記事