Re: nginx полностью загружает весь процессор при reload'e

Dmitry Sergeev identw на gmail.com
Вт Авг 27 11:39:48 UTC 2019


Прошу прощения, особенности почтового клиента.

Конфиг такой:

user www-data;
worker_processes auto;
worker_cpu_affinity auto;
worker_rlimit_nofile 65000;
pid /var/run/nginx.pid;

events
{
     worker_connections 10000;
     multi_accept off;
}

http
{
     ##
     # Basic Settings
     ##

     sendfile on;
     tcp_nopush on;
     tcp_nodelay on;
     keepalive_timeout 10;
     types_hash_max_size 2048;
     server_tokens on;

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

     client_body_timeout 60;
     client_header_timeout 60;
     send_timeout 60;
     reset_timedout_connection on;

     ##
     # Logging Settings
     ##

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

     #
     # Caching FS
     #
     open_file_cache max=10000;
     open_file_cache_errors on;


     ##
     # Gzip Settings
     ##

     gzip on;
     gzip_disable "msie6";
     gzip_types text/plain text/css application/json 
application/x-javascript text/xml application/xml application/xml+rss 
text/javascript application/javascript application/octet-stream;

     ##
     # Maps
     ##
     map $status $status_error
     {
             "~*^(1|2|3)"      0;
             default         1;
     }

     ##
     # Virtual Host Configs
     ##

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

И пример конфига виртуальных хостов для nodejs и php:
upstream nodejs_backend
{
     ip_hash;
     keepalive 32;
     server server1:4201 weight=1;
     server server2:4201 weight=3;
}


log_format file_c escape=json 
'{"HOST":"$host","LOCATION":"$location","IP":"$remote_addr","PROJECT":"nodejs_backend","HTTP_STATUS":"$status","RESPONSE_TIME":"$request_time","UPSTREAM_CONNECT_TIME":"$upstream_connect_time","UPSTREAM_RESPONSE_TIME":"$upstream_response_time","REQUEST_METHOD":"$request_method","REQUEST_FILE":"$uri","ARGS":"$args","BYTES_SENT":"$bytes_sent","USER_AGENT":"$http_user_agent","HTTP_REFERER":"$http_referer","ENVIRONMENT":"production","AKAMAI_IP":"$http_true_client_ip","HEADER_ACCEPT":"$http_accept","HEADER_ACCEPT_LANGUAGE":"$http_accept_language","HEADER_CONTENT_LANGUAGE":"$http_content_language","HEADER_CONTENT_TYPE":"$http_content_type","BODY":"$request_body"}';

server
{
     listen [::]:80;
     listen 80;
     # SSL
     listen [::]:443 ssl http2;
     listen 443 ssl http2;
     ssl_certificate /etc/nginx/ssl/fullchain.pem;
     ssl_certificate_key /etc/nginx/ssl/privkey.pem;

     server_name nodejs_domain;
     root /var/www/nodejs_domain/docroot;

     ###Logs
     # Local logs
     access_log /var/log/nginx/nodejs_domain_access.log 
file_nodejs_backend if=$status_error;
     error_log /var/log/nginx/nodejs_domain_error.log;


     location = /robots.txt
     {
         set $location "robots";
         return 200 "User-agent: *\nDisallow: /\n";
     }

     location = /https:/nodejs_domain
     {
         set $location "ssl_checker";
         return 200 "for ssl checker\n";
     }

     location ~ /\.(git|svn|hg)
     {
             deny all;
     }

     location /
     {
         try_files /bpcZzfcaG82kpcm9Xxic8hWJ89YjqrJCRihmHGGmBqFnU6gV 
@backend;
     }

     location @backend
     {
         set $location "nodejs";
         proxy_pass http://nodejs_backend;
         proxy_http_version 1.1;
         proxy_set_header Connection "";
         proxy_read_timeout 10s;

         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     }

     location /.well-known
     {
         set $location "well-known";
         root   /usr/share/nginx/html;
     }
}

пример конфига для php:

upstream php_backend
{
     ip_hash;
     server server6:4301 weight=1;
}


log_format file_php_domain escape=json 
'{"HOST":"$host","LOCATION":"$location","IP":"$remote_addr","PROJECT":"php_backend","HTTP_STATUS":"$status","RESPONSE_TIME":"$request_time","UPSTREAM_CONNECT_TIME":"$upstream_connect_time","UPSTREAM_RESPONSE_TIME":"$upstream_response_time","REQUEST_METHOD":"$request_method","REQUEST_FILE":"$uri","ARGS":"$args","BYTES_SENT":"$bytes_sent","USER_AGENT":"$http_user_agent","HTTP_REFERER":"$http_referer","ENVIRONMENT":"production","AKAMAI_IP":"$http_true_client_ip","HEADER_ACCEPT":"$http_accept","HEADER_ACCEPT_LANGUAGE":"$http_accept_language","HEADER_CONTENT_LANGUAGE":"$http_content_language","HEADER_CONTENT_TYPE":"$http_content_type","BODY":"$request_body"}';

server
{
     listen [::]:80;
     listen 80;
     listen [::]:443 ssl http2;
     listen 443 ssl http2;
     ssl_certificate /etc/nginx/ssl/fullchain.pem;
     ssl_certificate_key /etc/nginx/ssl/privkey.pem;

     server_name php_domain;
     root /var/www/php_domain/docroot;

     access_log /var/log/nginx/php_domain_access.log file_php_domain 
if=$status_error;
     error_log /var/log/nginx/php_domain_error.log;


     location = /robots.txt
     {
         set $location "robots";
         return 200 "User-agent: *\nDisallow: /\n";
     }

     location = /https:/php_domain
     {
         set $location "ssl_checker";
         return 200 "for ssl checker\n";
     }

     location ~ /\.(git|svn|hg)
     {
             deny all;
     }

     location ~* ^/.*\.php$
     {
         try_files /DsHs5OrKH8nAkZAYQVbWqwWN1kQmRC9rISzowfDiHPOJqJT3 
@backend;
     }

     location /
     {
         index index.html index.php;
         set $location "default";
     }

     location ~* ^/.*\.html$
     {
         set $location "html";
         add_header P3P 'policyref="../../../common/site/p3p.xml", 
CP="NOI CURa ADMa DEVa TAIa"';
         expires epoch;
     }

     location ~* 
^/.*\.(eot|webp|plist|png|jpg|jpeg|ttf|otf|woff|woff2|mp3|ogg|swf|js|json|atlas)$
     {
         set $location "static";
         add_header Access-Control-Allow-Origin *;
         add_header Access-Control-Expose-Headers "Date";
         expires max;
     }

     location ~* ^/.*\.(css|gif|ico|mpeg|mpg|mp4|svg)$
     {
         set $location "static";
         expires max;
     }

     location @backend
     {
         set $location "php";

         fastcgi_pass php_backend;
         include fastcgi_params;
         fastcgi_index index.php;
         fastcgi_connect_timeout 10s;
         fastcgi_read_timeout 10s;
         fastcgi_send_timeout 10s;
         fastcgi_param X_HOST $remote_addr;
         fastcgi_param SCRIPT_FILENAME /docroot$fastcgi_script_name;
     }

     location = /main/site/index.html
     {
         set $location "index";
         add_header P3P 'policyref="../../../common/site/p3p.xml", 
CP="NOI CURa ADMa DEVa TAIa"';
         expires epoch;
     }

     location /.well-known
     {
         set $location "well-known";
         root   /usr/share/nginx/html;
     }
}

Остальные виртуальные хосты либо похожие либо чуть отличаются.

On 27/08/2019 16:17, Maxim Dounin wrote:
> Hello!
>
> On Tue, Aug 27, 2019 at 04:10:31PM +0500, Dmitry Sergeev wrote:
>
>> Добрый день. Спасибо за ответ!
> Пожалуйста.  Не надо отвечать мне лично, от этого карма портится.
> Спасибо.
>
>> На сервере всего 64GB памяти, nginx кушает обычно около 2GB при релоадет
>> не сильно больше - 2-3GB, swap не задействуется. Свободно памяти обычно
>> больше 60GB.
>>
>> Сейчас протестил. При релоаде съедает весь проц ровно 35-40 секунд.
>> Провел около 10 тестов, время всегда примерно такое.
> Значит проблема не в памяти, а в чём-то ещё.  Что в конфиге?
>
-- 
Kind regards
Dmitry Sergeev
Tel: +7 (951) 129-75-72



Подробная информация о списке рассылки nginx-ru