We use Nginx across multiple servers and are currently running 1.11.10.
I am creating an Ansible script to deploy some configuration changes. The script copies the new configuration file to the server and then issues a command to reload the Nginx configuration.
Is there any way I can confirm that the file has been reloaded successfully? Using "systemctl status nginx" at the command line just gives me the status of the server and details when it was last restarted, not when the configuration was last reloaded.
Many thanks in advance for any information or help.
That nginx -s reload
return success(echo $?) tell us nginx load configurations successfully, but now the latest configuration may not worker for every request, because there maybe some connections with old worker are still not finished, at this time, the system has double worker processes as configured.
master-worker mode
The master process load the new configurations and spawn new worker processes with it, then stop the the old worker process after they finish the already existed connections
let's try with worker_processes 2;
✗ ./sbin/nginx
✗ ps aux|grep nginx
larryhe 2572 Ss 2:43PM 0:00.00 nginx: master process ./sbin/nginx
larryhe 2575 S 2:43PM 0:00.00 nginx: worker process
larryhe 2573 S 2:43PM 0:00.00 nginx: worker process
✗ ./sbin/nginx -s reload
✗ ps aux|grep nginx
larryhe 2572 Ss 2:43PM 0:00.01 nginx: master process ./sbin/nginx
larryhe 2706 S 2:44PM 0:00.00 nginx: worker process
larryhe 2705 S 2:44PM 0:00.00 nginx: worker process
The second column is pid
, we can see that pids of worker processes are different before and after reload
.
single-master mode
The master process apply the latest configuration within the process without restarting, it's done if nginx -s reload
returns success.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With