A
A
andrei_pro2020-03-21 00:44:07
Nginx
andrei_pro, 2020-03-21 00:44:07

Can't handle nginx?

Hello.

Cloud server: 4 cpu, 8 ram. It costs nginx as a proxy to other servers and rabbitmq in docker containers, logs are included.
Traffic ~70k rpm. With > traffic, lags appear on other servers - php-fpm grows, requests do not reach.

Suspicion that nginx needs more resources?

user nginx;
worker_processes auto;
pid /var/run/nginx.pid;

load_module modules/ngx_http_vhost_traffic_status_module.so;

events {
    use epoll;
    worker_connections 2048;
    multi_accept on;
}

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    send_timeout 2;
    keepalive_timeout 30;
    client_body_timeout 10;
    reset_timedout_connection on;
    types_hash_max_size 2048;
    # server_tokens off;
    server_names_hash_bucket_size 128;
    # server_name_in_redirect off;

    open_file_cache max=200000 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 2;
    open_file_cache_errors on;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    # https://docs.docker.com/v17.09/engine/userguide/networking/configure-dns/
    # Note: The DNS server is always at 127.0.0.11
    resolver 127.0.0.11 valid=5s;

    ssl_prefer_server_ciphers on;
    ssl_protocols             TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers               HIGH:!aNULL:!MD5;
    ssl_session_cache   shared:SSL:10m;

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

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    vhost_traffic_status_zone;
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}


5e7539d703dc9287530153.png

Answer the question

In order to leave comments, you need to log in

5 answer(s)
I
Ivan Shumov, 2020-03-21
@inoise

So, what we have is a cloud of everything on one server, which is already bad. It's a great time to think about scaling. What can you do to get started:

  1. take a few cheaper virtual machines
  2. separate nginx, rabbitmq
  3. think about getting rid of docker. the last time I saw it work well in large clouds like AWS ECS, but not on individual VPS
  4. configure horizontal scaling and dns-round-robin

also:
  • Let me remind you that the number of ports is limited and with a large number of simultaneous connections, they can stupidly end
  • the application layer should also be scaled

B
Badbuka, 2020-03-21
@Badbuka

Judging by LA, you lack 2x cpu

M
metajiji, 2020-03-21
@metajiji

It looks like nginx is using a lot of cpu.
The config is not complete, so I will assume that:
1. there are a lot of regex rules in the configs and they are not optimal.
2. For some reason, ports to nginx are forwarded through docker-proxy (I strongly recommend that you never do port forwarding in production!, Docker proxy is written in go and requires a lot of CPU! The solution to the problem is simple --net host, when creating a container with nginx 3.
Configured gd compression through nginx, hence the traffic to the cpu.The decision is either not to generate them on the fly, or move them to another host.The
full nginx config can be seen with the nginx -T command (I write from memory, check the help :))

A
Alexey Blyshko, 2020-03-21
@nekt

Yes

P
Puma Thailand, 2020-03-22
@opium

Well, increase the processors to 8 pieces from four, if it is already obvious that they are not enough

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question