0

I have a very low traffic Nginx box that serves as a reverse proxy to an external service. I have Monit on the box to restart nginx if it crashes. Needless to say, nginx stops at least once a day on this machine, and monit has to restart it.

Here's my monit configuration:

check process nginx with pidfile /var/run/nginx.pid
    start program = "/etc/init.d/nginx start"
    stop program  = "/etc/init.d/nginx stop"
    if cpu > 60% for 2 cycles then alert
    if cpu > 80% for 25 cycles then restart
    if totalmem > 400.0 MB for 5 cycles then restart
    if children > 250 then restart
    if loadavg(5min) greater than 10 for 8 cycles then stop
    if failed host 127.0.0.1 port 80 protocol http
       then restart
    if 3 restarts within 5 cycles then timeout

Here's my site config on nginx:

server {
    listen       80;
    server_name  somedomainname.com;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    location / {
        proxy_pass         https://somedomainname.com;
        proxy_redirect     off;

        client_max_body_size       10m;
        client_body_buffer_size    128k;

        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         90;

        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;
    }
}
slm
  • 7,355
  • 16
  • 54
  • 72
blefko
  • 23
  • 2
  • "Needless to say"? There must be a reason for this. What do your logs show? – ceejayoz Jul 31 '13 at 16:19
  • Nginx shows a 499 in the logs for the monit tests, which according to wikipedia means: Used in Nginx logs to indicate when the connection has been closed by client while the server is still processing its request, making server unable to send a status code back. How do I get monit to not close the connection, and why is that happening? It doesn't happen all the time. – blefko Jul 31 '13 at 16:37

1 Answers1

1

Your issue could be due to monit not sending a 'Host:' header field. Try addressing this by setting up a location for monit to monitor that is not proxied:

location = /test_target.html {
    root /var/www/public;
}

(I found this answer by searching for nginx monit 499. It was the first result.)

Mark Stosberg
  • 3,771
  • 23
  • 27