Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How nginx reload work ? why it is zero-downtime

Tags:

nginx

refer to nginx official docs . the reload command of nginx is for reload of configuration files ,and during the progress , there's no downtime of the service .

i've learned that it wait requests that already connected until it finished ,and stop accept any new request . the idea is cool , but how does it deal with the keep-live connections ? because those long-live connections won't close and there continuous request comes along .

like image 280
Adams.H Avatar asked Mar 29 '17 08:03

Adams.H


People also ask

How long does nginx take to reload?

Reloading in the panel (VPS and Dedicated Servers) Wait 5 minutes for it to rebuild the configuration file.

Is nginx reload safe?

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.

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 .

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.


1 Answers

Here's the summary:

http://nginx.org/en/docs/control.html

The master process first checks the syntax validity, then tries to apply new configuration. If this succeeds, it starts new worker processes, and sends messages to old worker processes requesting them to shut down gracefully.

That means it would keep older processes handling unclosed connections while having new processes working according to the updated configuration. From this perspective connections with keep-alive are no different from other unclosed connections.

In versions prior to 1.11.11 such "old" processes could hang indefinitely long (according to @Alexey, haven't checked it though), from 1.11.11 there’s a configuration setting controlling this http://nginx.org/en/docs/ngx_core_module.html#worker_shutdown_timeout

like image 69
ffeast Avatar answered Sep 19 '22 20:09

ffeast