大网数据广告活动
服务器运维问答

NGINX doesn't apply variables in /etc/default/nginx

· 52CE 我爱测

I've have just updated one of my servers from debian 6 to debian 8. Previously everything worked fine. Now, NGINX fails to start with the correct configuration. I have set up /etc/default/nginx to look like: DAEMON_OPTS="-c /etc/…

问题原文

原帖链接 · Xiflado · CC BY-SA 3.0

I've have just updated one of my servers from debian 6 to debian 8. Previously everything worked fine. Now, NGINX fails to start with the correct configuration.

I have set up /etc/default/nginx to look like:

DAEMON_OPTS="-c /etc/nginx/my.nginx.file.conf"
DAEMON_ARGS=$DAEMON_OPTS

This should make NGINX start with using a custom configuration file set in /etc/nginx/my.nginx.file.conf instead of the standard /etc/nginx/nginx.conf.

I've checked the init.d script and it has:

# Include nginx defaults if available
if [ -r /etc/default/nginx ]; then
        . /etc/default/nginx
fi

But it doesn't seem to apply. If I remove the file /etc/nginx/nginx.conf and leave my configuration file, I'll get the following:

# /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.

If I keep the file /etc/nginx/nginx.conf, NGINX will simply start using that file and not my own, i.e. /etc/nginx/my.nginx.file.conf. What am I doing wrong?

I'm trying to avoid to edit the init.d script if possible. I do know that I could setup DAEMON_OPTS there.

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 3.0

What you did wrong was to create your own /etc/nginx/my.nginx.file.conf instead of editing /etc/nginx/nginx.conf. Put the file back in its standard location.

Debian 8 has (finally) moved to systemd, and the old init script and /etc/default/nginx are no longer used. Of course, this was a bad idea even when they were in use, but it's especially a bad idea now.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-04-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。