nginx无法启动 - 排除故障

时间:2016-10-26 04:48:25

标签: nginx chef systemd nginx-location journal

我有一个简单的nginx配置,语法正确。我使用厨师安装nginx,厨师脚本工作正常。

但是当我检查nginx的状态时,我发现它处于失败状态。如果我重新加载nginx,它会再次进入失败状态。 journalctl -xn 也不会产生太多错误,除了:

    [root@localhost vagrant]# journalctl -xn
-- Logs begin at Wed 2016-10-26 04:28:18 UTC, end at Wed 2016-10-26 04:45:00 UTC. --
Oct 26 04:45:00 localhost.localdomain kill[17003]: -s, --signal <sig>     send specified signal
Oct 26 04:45:00 localhost.localdomain kill[17003]: -q, --queue <sig>      use sigqueue(2) rather than kill(2)
Oct 26 04:45:00 localhost.localdomain kill[17003]: -p, --pid              print pids without signaling them
Oct 26 04:45:00 localhost.localdomain kill[17003]: -l, --list [=<signal>] list signal names, or convert one to a name
Oct 26 04:45:00 localhost.localdomain kill[17003]: -L, --table            list signal names and numbers
Oct 26 04:45:00 localhost.localdomain kill[17003]: -h, --help     display this help and exit
Oct 26 04:45:00 localhost.localdomain kill[17003]: -V, --version  output version information and exit
Oct 26 04:45:00 localhost.localdomain kill[17003]: For more details see kill(1).
Oct 26 04:45:00 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1
Oct 26 04:45:00 localhost.localdomain systemd[1]: Unit nginx.service entered failed state.
[root@localhost vagrant]#

nginx -t成功,我在/var/log/nginx/errors.log中看不到任何内容

有没有其他方法可以解决为什么会失败?

systemctl status nginx.service都给出:

[root@localhost vagrant]# systemctl status nginx.service
nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; static)
   Active: failed (Result: exit-code) since Wed 2016-10-26 04:45:00 UTC; 9h ago
  Process: 17003 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=1/FAILURE)
  Process: 16999 ExecStart=/opt/nginx-1.10.1/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 16998 ExecStartPre=/opt/nginx-1.10.1/sbin/nginx -t (code=exited, status=0/SUCCESS)
 Main PID: 16999 (code=exited, status=0/SUCCESS)

Oct 26 04:45:00 localhost.localdomain kill[17003]: -s, --signal <sig>     send specified signal
Oct 26 04:45:00 localhost.localdomain kill[17003]: -q, --queue <sig>      use sigqueue(2) rather than kill(2)
Oct 26 04:45:00 localhost.localdomain kill[17003]: -p, --pid              print pids without signaling them
Oct 26 04:45:00 localhost.localdomain kill[17003]: -l, --list [=<signal>] list signal names, or convert one to a name
Oct 26 04:45:00 localhost.localdomain kill[17003]: -L, --table            list signal names and numbers
Oct 26 04:45:00 localhost.localdomain kill[17003]: -h, --help     display this help and exit
Oct 26 04:45:00 localhost.localdomain kill[17003]: -V, --version  output version information and exit
Oct 26 04:45:00 localhost.localdomain kill[17003]: For more details see kill(1).
Oct 26 04:45:00 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1
Oct 26 04:45:00 localhost.localdomain systemd[1]: Unit nginx.service entered failed state.

systemctl cat nginx.service给出:

[root@virsinplatformapi02 sysadmin]# systemctl cat nginx.service
Unknown operation 'cat'.

我cd cd / lib / systemd / system并在nginx.service上执行cat:

[root@virsinplatformapi02 system]# cat nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
ExecStartPre=/opt/nginx-1.10.1/sbin/nginx -t
ExecStart=/opt/nginx-1.10.1/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]

如果我使用echo $ MAINPID,我什么也得不到。

1 个答案:

答案 0 :(得分:0)

那个单元文件不是很好。未设置类型,默认为simple,而您希望forking为nginx。这可能是错误$MAINPID值的原因。尝试使用official unit

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/opt/nginx-1.10.1/sbin/nginx -t
ExecStart=/opt/nginx-1.10.1/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

您应该将其添加到/etc/systemd/system/nginx.service - 用于管理员创建的单位的目录,并具有优先权。