i have installed nginx in ubuntu16.04, and check that Configuration file location is /etc/nginx/conf/nginx.conf

$ /usr/sbin/nginx -V 2>&1 | grep --colour=auto conf

then Show Configuration file path:


I am working on Install openam nginx Webagent link, this nginx_agent have one nginx.conf file

nginx_web_agent install path:


nginx_web_agent nginx.conf path:


nginx_web_agent use that nginx.conf file,

How can i change nginx default nginx.conf file to nginx_web_agent nginx.conf file

for example:

nginx Configure use /opt/nginx_agent/conf/nginx.conf instead of /etc/nginx/nginx.conf

Suggest me How can i do that?

1 Answer 1


/usr/sbin/nginx -V shows the initial configure script parameters, not necessarily the actual parameters that are running.

To use an alternative configuration file, instead on the default one, you can set the -c flag (man nginx) :

/usr/sbin/nginx -c /opt/nginx_agent/conf/nginx.conf

Ubuntu 16.04 uses systemd to manage services, so you will need to change systemd parameters for nginx service :

  1. Edit /lib/systemd/system/nginx.service
  2. Add -c flag where required :

    ExecStartPre=/usr/sbin/nginx -t -c /opt/nginx_agent/conf/nginx.conf -q -g 'daemon on; master_process on;'
    ExecStart=/usr/sbin/nginx -c /opt/nginx_agent/conf/nginx.conf -g 'daemon on; master_process on;'
    ExecReload=/usr/sbin/nginx -c /opt/nginx_agent/conf/nginx.conf -g 'daemon on; master_process on;' -s reload
  3. Reload the systemd manager configuration : systemctl daemon-reload

  4. Start nginx service :

    service nginx start
  5. Check nginx service parameters :

    systemctl status nginx.service
    2411 nginx: master process /usr/sbin/nginx -c /opt/nginx_agent/conf/nginx.conf -g daemon on; master_process on

This is the way i would do it.

  • 2
    Do not edit the system nginx.service directly. It may be restored whenever you upgrade the package. Instead, provide your overrides in /etc/systemd/system/nginx.service.d/whatever.conf. Dec 17, 2016 at 13:15
  • @krisFR I have used ubuntu16.04 docker, docker have issue to Since systemd isn't running as init inside your docker container, there's no daemon to process your start and stop commands. reference: stackoverflow.com/questions/39169403/… , so, Suggest me Any alternative way to change nginx configuration path. Dec 20, 2016 at 5:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.