当在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.