When to restart and not reload Nginx?
Asked Answered
E

4

69

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?

Edytheee answered 23/11, 2012 at 8:38 Comment(1)
I don't understand your last paragraph. Is that a question?Guardafui
B
73

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.

Byerly answered 23/11, 2012 at 10:50 Comment(4)
will a ngixn extension like modrails.com/documentation/Users%20guide%20Nginx.html make any difference ?Edytheee
Well, when using passenger it is usually wiser to restart application server instead of web server (in this case, by touching tmp/restart.txt file), but apart from that it should work exactly the same.Byerly
What if I nginx -t before to check syntax? What's the difference then?Jeniferjeniffer
From nginx guide: Once the master process receives the signal to reload configuration, it checks the syntax validity of the new configuration file and tries to apply the configuration provided in it. If this is a success, the master process starts new worker processes and sends messages to old worker processes, requesting them to shut down. Otherwise, the master process rolls back the changes and continues to work with the old configuration.Byerly
G
35

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

Guardafui answered 26/11, 2013 at 11:12 Comment(2)
I had the same experience just now... I was going crazy until I figured this out!!Motherinlaw
Ditto!, I spent days figuring out why docker containers can't resolve hostnames, and by simply restarting nginx instead of reloading, fixed it.Upbringing
J
16

Ztyx is right - restarting when changing a listen directive is required in some cases.

With 1.6.x, you can reload when changing the listen IP address, but you need to restart when listening from "*:80" to an IP address "x.x.x.x:80".

I have only confirmed this with IPv4, behavior for IPv6 may be similar.

Jessee answered 25/8, 2014 at 21:49 Comment(0)
R
1

If you really need to restart nginx. First, you could run below command to check if you have any errors.

 sudo nginx -t

Reload is better option in most of the time.

reload – Reload the configuration file.

Rwanda answered 9/11, 2023 at 14:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.