Search code examples
nginxmonit

Is there a way to automatically restart nginx with monit when it doesnt respond with status 200


Is there a way to automatically restart nginx with monit when it doesnt respond with status 200

The server seems to handle most of the requests but tends to lock up for a minute or two when it gets overwhelmed with requests. So I would like to have it check if the request responds to 504/502 to restart nginx


Solution

  • A simple sample to handle nginx is available from https://mmonit.com/wiki/Monit/ConfigurationExamples#NginX and from https://www.mmonit.com/monit/documentation/monit.html#CONFIGURATION-EXAMPLES some other samples are available.

    And there are general information about handling the http status code from https://www.mmonit.com/monit/documentation/monit.html#HTTP

    You can setup the Monit to test in shorter intervals, but one or two minutes is a good interval size (in general, from my point of view). In the Monit configuration monitrc file you can use a shorter interval.

    set daemon 60 # check services at 60 seconds intervals

    But you should not use a interval below 30 seconds (I prefer 60 seconds).