Обратный прокси-сервер Nginx https слишком медленный

Я реализовал кеш Nginx с обратным прокси-сервером https в centos, мое время ответа занимает более 1,5 секунд для каждого запроса. Моя конфигурация сервера nginx была 4 ядра, 8 ГБ оперативной памяти.

Моя конфигурация выглядит следующим образом (nginx.config)

      `user nginx;
worker_processes auto;
worker_rlimit_nofile 100000;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

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


http {
   
    ssl_session_cache   shared:SSL:10m;
    ssl_session_timeout 10m;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    log_format rt_cache '$remote_addr - $upstream_cache_status [$time_local]  '
                      '"$request" $status $body_bytes_sent '
                      '"$http_referer" "$http_user_agent"';

    # Below pattern will print
    # Time stamp | Client IP | client Dev apps Name| Request | Status Returned| Time taken in ms| size Returned in bytes| Referer | hit or miss | User agent
    log_format bf_log_format '[$time_local]|'
                             '$remote_addr|'
                             '$http_x_developer_username|$http_x_forwarded_for|'
                             '"$request"|'
                             '$status|$upstream_response_time|$body_bytes_sent|'
                             '"$http_referer"|'
                             '"$upstream_cache_status"|'
                             '"$http_user_agent"';

     log_format json_log_format escape=json '{'
                                 '"time": "$time_iso8601",'
                                 '"trace_id": "$request_id",'
                                  '"http": {'
                                     '"body_bytes_sent": "$body_bytes_sent",'
                                     '"x_developer_username": "$http_x_developer_username",'
                                     '"remote_addr": "$remote_addr",'
                                     '"method": "$request_method",'
                                     '"request": "$request_uri",'
                                     '"schema": "$scheme",'
                                     '"request_time": "$request_time",'
                                     '"host": "$host",'
                                     '"uri": "$uri",'
                                     '"user_agent": "$http_user_agent",'
                                     '"status": "$status"'
                                  '},'
                                  '"proxy": {'
                                     '"host": "$proxy_host"'
                                  '},'
                                  '"upstream": {'
                                     '"response_time": "$upstream_response_time sec",'
                                     '"cache_status": "$upstream_cache_status"'
                                   '}'
                                 '}';

   #  access_log  /var/log/nginx/access.log  main;
#    access_log   /var/log/nginx/access.log json_log_format;
    access_log off;

    sendfile            on;
    sendfile_max_chunk 512k;
    # directio 4m;
    # directio_alignment 512;
    tcp_nopush          on;
    tcp_nodelay         on;

    reset_timedout_connection on;

    keepalive_requests 100000;
    types_hash_max_size 2048;

    # reduce the data that needs to be sent over network -- for testing environment
    gzip on;
    # gzip_static on;
    gzip_min_length 10240;
    gzip_comp_level 1;
    gzip_vary on;
    gzip_disable msie6;
    gzip_proxied expired no-cache no-store private auth;
    gzip_types
        text/css
        text/javascript
        text/xml
        text/plain
        text/x-component
        application/javascript
        application/x-javascript
        application/json
        application/xml
        application/rss+xml
        application/atom+xml
        font/truetype
        font/opentype
        application/vnd.ms-fontobject
        image/svg+xml;

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

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.


    proxy_cache_path /opt/nginx/cache levels=1:2 keys_zone=api-cache:3000m max_size=100g inactive=43200m use_temp_path=off;
    proxy_temp_path /opt/nginx/cache/other;

    include /etc/nginx/conf.d/ssl.conf;
}` 

Мой ssl.confg выглядит так:

       server {

    server_name  _;
    root         /usr/share/nginx/html;

    listen       443 ssl http2 default_server;
    listen       [::]:443 ssl;

    ssl_certificate     "/etc/private/ssl/cert.pem";
    ssl_certificate_key "/etc/private/ssl/key.pem";
    # ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;
    keepalive_timeout   100;


    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }

    location /health {
       default_type application/json;
       return 200 '{"status":"UP"}';
    }
    location /nginx-status {
        stub_status;
    }

    location /trellotest {
        proxy_cache_bypass $http_no_cache_purge $arg_nocache;
        proxy_cache_methods GET POST;
        add_header Cache-Control "public";
        proxy_cache api-cache;
        proxy_cache_valid 200 40320m;
        add_header X-Cache $upstream_cache_status;
        add_header X-Time $request_time;
        proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
        proxy_pass https://mytrelloapp;
    }
}

Если возможно, кто-нибудь, не могли бы вы посоветовать мне, нужно ли нам в любом случае улучшить вышеуказанные конфигурации?

0 ответов

Другие вопросы по тегам