我刚刚将我的一台服务器从 Debian 6 更新到 Debian 8。以前一切正常。现在,NGINX 无法以正确的配置启动。
我已经设置/etc/default/nginx
成如下的样子:
DAEMON_OPTS="-c /etc/nginx/my.nginx.file.conf"
DAEMON_ARGS=$DAEMON_OPTS
这应该使 NGINX 启动时使用自定义配置文件设置/etc/nginx/my.nginx.file.conf
而不是标准配置文件设置/etc/nginx/nginx.conf
。
我检查了init.d
脚本并且它具有:
# Include nginx defaults if available
if [ -r /etc/default/nginx ]; then
. /etc/default/nginx
fi
但这似乎不适用。如果我删除该文件/etc/nginx/nginx.conf
并保留我的配置文件,我将得到以下内容:
# /etc/init.d/nginx start
[....] Starting nginx (via systemctl): nginx.serviceJob for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details.
failed!
# systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
Active: failed (Result: exit-code) since Fri 2016-04-22 14:35:14 UTC; 6s ago
Process: 12772 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
Process: 3773 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=0/SUCCESS)
Process: 12738 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 5193 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Main PID: 12740 (code=exited, status=0/SUCCESS)
Apr 22 14:35:14 xxx nginx[5193]: nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
Apr 22 14:35:14 xxx nginx[5193]: nginx: configuration file /etc/nginx/nginx.conf test failed
Apr 22 14:35:14 xxx systemd[1]: nginx.service: control process exited, code=exited status=1
Apr 22 14:35:14 xxx systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Apr 22 14:35:14 xxx systemd[1]: Unit nginx.service entered failed state.
如果我保留文件/etc/nginx/nginx.conf
,NGINX 将开始使用该文件而不是我自己的文件,即/etc/nginx/my.nginx.file.conf
。我做错了什么?
如果可能的话,我尽量避免编辑init.d
脚本。但我知道我可以在那里设置 DAEMON_OPTS。
答案1
您做错的是创建了自己的文件,/etc/nginx/my.nginx.file.conf
而不是编辑/etc/nginx/nginx.conf
。将文件放回其标准位置。
Debian 8 终于迁移到 systemd,旧的 init 脚本和/etc/default/nginx
不再使用。当然,即使在使用它们时,这也是一个坏主意,但现在尤其糟糕。