call openresty's nginx.conf file while running service start/stop/restart nginx command

8.6k views Asked by At

I am using nginx as web server to my Django project.
I am using command

sudo service nginx start/stop/restart 
to manage nginx server. Now i am using Openresty framework to implement Lua code into nginx server to handle Cache system.
Openrestry provides it's own nginx.conf file. Requirement : Now i want then when i run
sudo service nginx start/stop/restart 
system should call nginx.conf file from Openresty folder(/usr/local/openresty/nginx/conf/nginx.conf in place of /etc/nginx/nginx.confM file.
How can i achieve this ???

4

There are 4 answers

0
Prashant Gaur On BEST ANSWER

You should go to

cd /etc/init.d 
vim nginx.conf
#Edit PATH , DAEMON variable
PATH=/usr/local/openresty/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/openresty/nginx/sbin/nginx
 

Now when you will run sudo service nginx start/stop/restart it will call nginx.conf file from openresty folder. While /usr/local/openresty is the path where Openresty is installed by default

0
ig0r On

If you want to use that nginx instead of your old nginx you can set

DAEMON_OPTS=" -c usr/local/openresty/nginx/conf/nginx.conf "

in "/etc/default/nginx"

In that case you can manage nginx as usual

sudo service nginx start/stop/restart

but your configuration in /etc/nginx/nginx.conf will not work.

3
jpic On

Use the -c option:

  -c filename   : set configuration file (default: /etc/nginx/nginx.conf)

ie.

sudo service nginx -c /usr/local/openresty/nginx/conf/nginx.conf start/stop/restart 

You can make an alias:

alias service_openresty="sudo service nginx -c /usr/local/openresty/nginx/conf/nginx.conf"

And run:

service_openresty start/stop/reload

This is the only safe approach because it won't get overwritten by package updates.

0
naartjie On

I know this is an old thread, but the author of openresty (agentzh) recommends creating a new openresty service by copying your /etc/init.d/nginx to /etc/init.d/openrestify and modifying the paths to match your custom openresty install. This is to prevent polluting your system's default config files. Please see this mailing list post.