Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to restart and not reload Nginx?

When is it necessary to restart nginx and reload will not suffice?
Does it make a difference if an extension like passenger is used?

Should the service be restarted if it consumes too much memory. Any other reasons for restarting Nginx, particularly after a configuration change either in an extension or a Nginx core config?

After making a configuration change, one can either restart or reload nginx, via the binary itself or the init.d script "/etc/init.d/nginx -h" on Ubuntu. Which method should be preferred?

like image 276
deepak Avatar asked Nov 23 '12 08:11

deepak


People also ask

Is it safe to restart nginx?

Reloading nginx is safer than restarting because before old process will be terminated, new configuration file is parsed and whole process is aborted if there are any problems with it.

Do I need to restart nginx after config change?

You need to reload or restart Nginx whenever you make changes to its configuration. The reload command loads the new configuration, starts new worker processes with the new configuration, and gracefully shuts down old worker processes.

Does nginx auto reload config?

nginx -t will test the syntax of the configuration files and ensure that all configuration files referenced are accessible. If the Nginx configuration passes testing, then Nginx will be reloaded with nginx -s reload .


2 Answers

Reloading nginx is safer than restarting because before old process will be terminated, new configuration file is parsed and whole process is aborted if there are any problems with it.

On the other hand when you restart nginx you might encounter situation in which nginx will stop, and won't start back again, because of syntax error.

Reloading terminates the old process, so any memory leaks should be cleared anyway.

like image 156
samuil Avatar answered Oct 14 '22 21:10

samuil


I've experienced a case where I needed to restart nginx to have listen directives for a new IP adress kick in.

like image 44
Ztyx Avatar answered Oct 14 '22 23:10

Ztyx