Gracefully restart Nginx

Follow these 3 steps to gracefully stop and start Nginx without losing any queries. It works like a charm.

  1. Test new configuration is correct
    nginx -t
  2. Find the Pid
    ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'
  3. And kill it. Meanwhile, new configuration is already effective.
    kill -HUP ????
    (replace ???? with the Pid given in step 2)

Leave a comment

Your email address will not be published. Required fields are marked *