nginx
AWS
5
どのような問題がありますか?

この記事は最終更新日から1年以上が経過しています。

投稿日

更新日

nginxの接続で「nginx: [emerg] unknown directive " "」が表示された時の対処法

はじめに

ngin.xに接続を試みるもエラーとなりました。

$ sudo systemctl start 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.

対処法

エラーコードの指示を実行。

$ systemctl status nginx.service
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 火 2019-09-17 20:53:03 UTC; 25s ago
     Docs: http://nginx.org/en/docs/
  Process: 3438 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)

 9月 17 20:53:03 ip-10-0-0-133.ap-northeast-1.compute.internal systemd[1]: Starting nginx - high performance web server...
 9月 17 20:53:03 ip-10-0-0-133.ap-northeast-1.compute.internal nginx[3438]: nginx: [emerg] unknown directive " " in /etc/nginx/nginx.conf:44
 9月 17 20:53:03 ip-10-0-0-133.ap-northeast-1.compute.internal systemd[1]: nginx.service: control process exited, code=exited status=1
 9月 17 20:53:03 ip-10-0-0-133.ap-northeast-1.compute.internal systemd[1]: Failed to start nginx - high performance web server.
 9月 17 20:53:03 ip-10-0-0-133.ap-northeast-1.compute.internal systemd[1]: Unit nginx.service entered failed state.
 9月 17 20:53:03 ip-10-0-0-133.ap-northeast-1.compute.internal systemd[1]: nginx.service failed.

不要な空白" "が入ってしまって、そんな指令知らないと怒られていました。それが/etc/nginx/nginx.conf:44にあるとのこと。

$ sudo vi /etc/nginx/nginx.conf
  :set number  #44行目を探すため、行数表示
 不要な空白を削除。おそらく全角の空白があった。

最初、行数数えていましたので(笑)、:set numberは便利ですね。カーソルモード(ESCを押したあとの状態)で入力です。

再度接続すると、無事接続できました。

$ sudo systemctl start nginx.service
$ sudo systemctl status nginx.service  #接続状況の確認
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since 火 2019-09-17 21:32:13 UTC; 3min 56s ago
     Docs: http://nginx.org/en/docs/
  Process: 3592 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 3593 (nginx)
   CGroup: /system.slice/nginx.service
           ├─3593 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
           └─3595 nginx: worker process

 9月 17 21:32:13 ip-10-0-0-133.ap-northeast-1.compute.internal systemd[1]: Starting nginx - high performance web server...
 9月 17 21:32:13 ip-10-0-0-133.ap-northeast-1.compute.internal systemd[1]: PID file /var/run/nginx.pid not readable (yet?) after start.
 9月 17 21:32:13 ip-10-0-0-133.ap-northeast-1.compute.internal systemd[1]: Started nginx - high performance web server.

参考

ユーザー登録して、Qiitaをもっと便利に使ってみませんか。
  1. あなたにマッチした記事をお届けします
    ユーザーやタグをフォローすることで、あなたが興味を持つ技術分野の情報をまとめてキャッチアップできます
  2. 便利な情報をあとで効率的に読み返せます
    気に入った記事を「ストック」することで、あとからすぐに検索できます
ユーザー登録ログイン
Takao_
AWS触ってます。 自身のスキルアップのため、時々記事を書きます。
この記事は以下の記事からリンクされています

コメント

この記事にコメントはありません。
あなたもコメントしてみませんか :)
ユーザー登録
すでにアカウントを持っている方はログイン
5
どのような問題がありますか?
ユーザー登録して、Qiitaをもっと便利に使ってみませんか

この機能を利用するにはログインする必要があります。ログインするとさらに下記の機能が使えます。

  1. ユーザーやタグのフォロー機能であなたにマッチした記事をお届け
  2. ストック機能で便利な情報を後から効率的に読み返せる
ユーザー登録ログイン
ストックするカテゴリー