Experiencing a lot of downtime

July 14, 2017 484 views
Apache Nginx Ubuntu 16.04

I'm using uptimerobot.com to measure the uptime of my server. Unfortunately it goes down a lot! Almost twice a day for maybe just one to two minutes. I can't find anything in my logs and am completely lost what is going wrong. I've looked at all log files and can't find anything out of the ordinary (apart from the 301 responses from uptimerobot.com). I have no clue what to look for now.

I'm using Varnish on port 80, Nginx on port 443 and Apache on port 8080. Both ports 80 and 443 are open. When I go to my site (quentinbuiteman.com) on all possible URL's, I just get there, so the configuration seems to be working correctly.

3 Answers
jtittle MOD July 14, 2017
Accepted Answer

@QuentinBuiteman

My initial thought would be that NGINX isn't passing on the headers that you're targeting when it proxies a request. In addition to proxy_pass, I normally run the following configuration:

        proxy_buffers 16 32k;
        proxy_buffer_size 64k;
        proxy_busy_buffers_size 128k;
        proxy_cache_bypass $http_pragma $http_authorization;
        proxy_connect_timeout 59s;
        proxy_hide_header X-Powered-By;
        proxy_http_version 1.1;
        proxy_ignore_headers Cache-Control Expires;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_404;
        proxy_no_cache $http_pragma $http_authorization;
        proxy_pass_header Set-Cookie;
        proxy_read_timeout 600;
        proxy_redirect off;
        proxy_send_timeout 600;
        proxy_temp_file_write_size 64k;
        proxy_set_header Accept-Encoding '';
        proxy_set_header Cookie $http_cookie;
        proxy_set_header Host $host;
        proxy_set_header Proxy '';
        proxy_set_header Referer $http_referer;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Original-Request $request_uri;

The above is pulled from my own configuration that I've used for some time in various setups (which includes WordPress behind a proxy).

I'd recommend testing that out and seeing if that helps. You'd want to restart NGINX once the changes are in place. From there, I'd be happy to check on my end to see if that resolves the issue I'm seeing on my end.

If it doesn't work, I'd check the logs to see if there's anything more than we can pinpoint.

tail -20 /var/log/nginx/error.log
  • Thanks a lot for the code and your help so far!

    I've added everything and restarted Nginx (and Apache and Varnish just in case).
    Could you check if you still have the same issue?

@QuentinBuiteman

When I visit your website, I'm seeing an error:

Too many redirects

... which would be a configuration issue that would, in most cases, be detected as downtime since it prevents your site from being displayed as expected.

...

1). Are you using Varnish + Apache, or Varnish + NGINX + Apache?

2). What kind of site is this (i.e. WordPress, static, NodeJS, etc)?

3). Are you using anything else in front (i.e. CloudFlare)?

  • That's really weird! I used to have that error, but I added this to my wordpress config, after which it was gone:

    if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
        $_SERVER['HTTPS'] = 'on';
    }
    

    Do you have any idea how it's possible that I'm not getting that error (also not on my work address). And most of the time uptimerobot.com also gets a 200 and not a 301.

    1) I'm using Varnish + Nginx + Apache. Nginx for static files, Apache for dynamic. I've got Varnish on port 80, Nginx on 443 and Apache on 8080. Porst 80 and 443 are open.

    2) It's a Wordpress website.

    3) Nothing in front.

@QuentinBuiteman

From what I can see on my end, things are looking good :-) -- looks like it's loading in less than a second on my end.

  • Thanks a lot! I haven't had another 301 from uptimerobot for over 24 hours now. Let's hope it stays that way and that this was it!

  • For some reason it's been acting up again the last two weeks, despite that I didn't make any changes. I can't get through a single day without it being down for a couple minutes and then back up again. There's nothing weird in the logs again. I've tried upgrading all packages and restarting, but to no avail. Do you have any idea what I could do next?

Have another answer? Share your knowledge.