0

我有一个语法正确的简单 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 ,我什么也得不到。

4

1 回答 1

0

那不是很好的单元文件。类型未设置,默认为simple,而你想要你forking的 nginx。这可能是错误$MAINPID值的原因。尝试使用官方单位

[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- 它用于管理员创建的单元的目录,并具有优先级。

于 2016-10-26T16:15:34.467 回答