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

Xiflado asked:

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.

My answer:


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.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.