2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2019-09-17

はじめに

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.

参考

2
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?