4

I have a quite small VPS on AWS (EC2 t2.nano) that is running an nginx server. while sometimes a sudo service nginx reload or nginx -t is blazing fast, most of the time it is horribly slow (>60 seconds) without any load on the server.

There are ~10 server blocks defined as proxies 3 of them with ssl enabled.

nginx-t -v does not give any clue, why it is so slow, I cannot find anything in the logs. RAM and CPU usage are quite low during that.

how can I investigate what makes a reload of nginx that slow, what are common thing, I could look for? DNS Resulutions? My upstreams are all defined as e.g.

upstream ent-pbmcom {
     ip_hash;            # for sticky sessions
     server 10.0.2.52:8080;
}

...

server {
     ...
     location / {
         add_header X-Block  "ent-pbmcom";
         add_header X-Upstream  $upstream_addr;
         add_header X-Requested-Host '$host';

         proxy_pass http://ent-pbmcom;

         proxy_set_header X-Real-IP $remote_addr;  # http://wiki.nginx.org/HttpProxyModule
         proxy_set_header Host $host;  # pass the host header - http://wiki.nginx.org/HttpProx$
         proxy_http_version 1.1;  # recommended with keepalive connections - http://nginx.org/$
         # WebSocket proxying - from http://nginx.org/en/docs/http/websocket.html
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection $connection_upgrade;

         proxy_redirect off;
     }
}
Tobi
  • 237
  • 3
  • 12
  • 1
    I run a t2.nano with five websites and around fifteen server blocks, nginx -t or nginx restart is subsecond. Have you run out of CPU credits? Have you run out of another resource, RAM or disk IO? You can tell in Cloudwatch, though RAM requires a custom metric. – Tim Jan 20 '17 at 00:54
  • Well, on this system there are basically no shortages. we do not really use the disc at all (so no IO problems) the Network has also no really high baseline, CPU credit is steady at arount 71 credits, usage between 0 and 0.3, ram is 60% full. – Tobi Jan 21 '17 at 18:12
  • Did you check Cloudwatch like I suggested? Check EC2, CPU and EBS credit usage. It's probably not that though. Have you considered reinstalling Nginx? How about building Nginx from source? It's pretty easy. https://www.photographerstechsupport.com/tutorials/hosting-wordpress-on-aws-tutorial-part-2-setting-up-aws-for-wordpress-with-rds-nginx-hhvm-php-ssmtp/#nginx-source – Tim Jan 21 '17 at 18:32
  • I checked credit usage, no problems there, switched to a t2.micro instance (by imaging the old instance), still same problem. `time nginx -t` tells me a time of 55.314 seconds, when I have 12 server blocks each with ssl enabled, but absolutely no load on the server (disabled port 80 and 443 via firewall for testing). this command also needs basically no cpu, but is just slow. – Tobi Jan 26 '17 at 01:52
  • Stop your server using the EC2 console, then start it again. This will trigger moving the virtual server to new hardware. Do not use restart, use stop, wait a few seconds, then start. There's a 5% chance you have a noisy neighbor, it probably won't fix it but it's so easy you might as well give it a go. The next step would either be to build a whole new server or have someone else try to reproduce the problem. – Tim Jan 26 '17 at 08:08

0 Answers0