質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

Q&A

2回答

1905閲覧

nginx.serviceの問題?

hiroroyayasu

総合スコア12

nginx

nginixは軽量で高性能なwebサーバーの1つです。BSD-likeライセンスのもとリリースされており、あわせてHTTPサーバ、リバースプロキシ、メールプロキシの機能も備えています。MacOSX、Windows、Linux、上で動作します。

0グッド

0クリップ

投稿2019/07/22 14:37

前提・実現したいこと

nginxでconfにrewriteを書き込んだ後、リロードしようとしたらnginx.serviceに問題があると言われてリロード、リスタートができません。

発生している問題・エラーメッセージ

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

と出てきます。

該当のソースコード

実際に見てみると、

● 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 Mon 2019-07-22 14:32:43 UTC; 1min 2s ago
Process: 21293 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=0/SUCCESS)
Process: 2205 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 21834 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE)
Main PID: 2211 (code=exited, status=0/SUCCESS)

Jul 22 14:32:43 kusanagi80 systemd[1]: Starting The NGINX HTTP and reverse .....
Jul 22 14:32:43 kusanagi80 nginx[21834]: nginx: [emerg] "server" directive i...3
Jul 22 14:32:43 kusanagi80 nginx[21834]: nginx: configuration file /etc/ngin...d
Jul 22 14:32:43 kusanagi80 systemd[1]: nginx.service: control process exite...=1
Jul 22 14:32:43 kusanagi80 systemd[1]: Failed to start The NGINX HTTP and r...r.
Jul 22 14:32:43 kusanagi80 systemd[1]: Unit nginx.service entered failed state.
Jul 22 14:32:43 kusanagi80 systemd[1]: nginx.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

Jul 22 14:32:43 kusanagi80 systemd[1]: Configuration file /usr/lib/systemd/syste
Jul 22 14:32:43 kusanagi80 polkitd[432]: Registered Authentication Agent for uni
Jul 22 14:32:43 kusanagi80 systemd[1]: Stopping HHVM virtual machine, runtime, a
-- Subject: Unit hhvm.service has begun shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel

-- Unit hhvm.service has begun shutting down.
Jul 22 14:32:43 kusanagi80 systemd[1]: Started HHVM virtual machine, runtime, an
-- Subject: Unit hhvm.service has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel

-- Unit hhvm.service has finished starting up.

-- The start-up result is done.
Jul 22 14:32:43 kusanagi80 systemd[1]: Starting HHVM virtual machine, runtime, a
-- Subject: Unit hhvm.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel

-- Unit hhvm.service has begun starting up.
Jul 22 14:32:43 kusanagi80 polkitd[432]: Unregistered Authentication Agent for u
lines 4687-4709/4709 (END)

と表記されます。

試したこと

ほぼ初心者で調べながら進めていたのですが、散々調べた結果限界を感じたので、ここで聞かせていただきます。

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

mit0223

2019/07/23 00:12

journalctl -l --no-pager -u nginx の結果(大きい場合は最後の20行くらい)を貼ってもらえますか。
hiroroyayasu

2019/07/23 09:01 編集

mit0223さん、ありがとうございます。 最後の20行くらいはこのように出てきました。 7月 22 13:14:09 kusanagi80 systemd[1]: Starting The NGINX HTTP and reverse proxy server... 7月 22 13:14:09 kusanagi80 nginx[21534]: nginx: [emerg] "server" directive is not allowed here in /etc/nginx/nginx.conf:3 7月 22 13:14:09 kusanagi80 nginx[21534]: nginx: configuration file /etc/nginx/nginx.conf test failed 7月 22 13:14:09 kusanagi80 systemd[1]: nginx.service: control process exited, code=exited status=1 7月 22 13:14:09 kusanagi80 systemd[1]: Failed to start The NGINX HTTP and reverse proxy server. 7月 22 13:14:09 kusanagi80 systemd[1]: Unit nginx.service entered failed state. 7月 22 13:14:09 kusanagi80 systemd[1]: nginx.service failed. 7月 22 13:22:23 kusanagi80 systemd[1]: Starting The NGINX HTTP and reverse proxy server... 7月 22 13:22:23 kusanagi80 nginx[21607]: nginx: [emerg] "server" directive is not allowed here in /etc/nginx/nginx.conf:3 7月 22 13:22:23 kusanagi80 nginx[21607]: nginx: configuration file /etc/nginx/nginx.conf test failed 7月 22 13:22:23 kusanagi80 systemd[1]: nginx.service: control process exited, code=exited status=1 7月 22 13:22:23 kusanagi80 systemd[1]: Failed to start The NGINX HTTP and reverse proxy server. 7月 22 13:22:23 kusanagi80 systemd[1]: Unit nginx.service entered failed state. 7月 22 13:22:23 kusanagi80 systemd[1]: nginx.service failed. 7月 22 14:32:43 kusanagi80 systemd[1]: Starting The NGINX HTTP and reverse proxy server... 7月 22 14:32:43 kusanagi80 nginx[21834]: nginx: [emerg] "server" directive is not allowed here in /etc/nginx/nginx.conf:3 7月 22 14:32:43 kusanagi80 nginx[21834]: nginx: configuration file /etc/nginx/nginx.conf test failed 7月 22 14:32:43 kusanagi80 systemd[1]: nginx.service: control process exited, code=exited status=1 7月 22 14:32:43 kusanagi80 systemd[1]: Failed to start The NGINX HTTP and reverse proxy server. 7月 22 14:32:43 kusanagi80 systemd[1]: Unit nginx.service entered failed state. 7月 22 14:32:43 kusanagi80 systemd[1]: nginx.service failed.
guest

回答2

0

7月 22 13:22:23 kusanagi80 nginx[21607]: nginx: [emerg] "server" directive is not allowed here in /etc/nginx/nginx.conf:3

「/etc/nginx/nginx.conf の3行目に書かれている server ディレクティブはここには書けません」と言われています。
設定ファイルが間違っているので、治してください。server ディレクティブは http { } の中に書かなければなりません。トップレベルに書くとこのエラーが出ます。

ちなみに journalctl コマンドはデフォルトでは less を伴って起動します。質問に貼っていただいたログでは肝心のところが見えてません。上矢印や左矢印キーを使って表示範囲を移動して、エラーメッセージを探す必要があります。
また、 -u nginx をつけることで、nginx 関連のログに絞ることができます。 journalctl -e -u nginx として矢印キーで上下左右に動かしてエラーメッセージを探すのがおすすめです。

less 操作が面倒であれば、 -l --no-pager オプションを付けることで回避できます。

投稿2019/07/23 09:38

mit0223

総合スコア3401

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hiroroyayasu

2019/07/23 10:29

できました! 丁寧に本当に大変ありがとうございます。助かりました。
mit0223

2019/08/14 06:16

解決したのであれば、お手数ですが、ベストアンサーを選択して解決済みにしていただけますでしょうか。
guest

0

設定ファイルに構文エラーがあります。
/usr/sbin/nginx -t を実行してエラーの内容を確認し、設定ファイルの構文エラーを修正してください。

下記が問題の箇所です。

Process: 21834 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE)

投稿2019/07/22 14:53

scsi

総合スコア2840

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hiroroyayasu

2019/07/23 09:04

ご回答大変ありがとうございます。 nginx: [emerg] "server" directive is not allowed here in /etc/nginx/nginx.conf:3 nginx: configuration file /etc/nginx/nginx.conf test failed こうなったのですが、nginx.confに問題があるのでしょうか。
scsi

2019/07/23 09:28

出力を読めば一目瞭然ですが、 nginx.conf の 3行目に 許可されていない server directive が書かれているようです。
hiroroyayasu

2019/07/23 10:29

そう言うことだったんですね、、、未熟すぎて申し訳ないです。 大変ありがとうございました!!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問