Микрокэш nginx для улучшения производительности drupal 7 - PullRequest
0 голосов
/ 10 октября 2018

Я хочу улучшить производительность сайта drupal.Уже были настройки для друпального кэша и расширенного агрегирования CSS / JS.Также реализованы изменения, запрошенные gtmatix , тем не менее загрузка занимает 20 секунд.Также реализован кэш fastcgi, но без улучшений.Ниже приведены мои настройки nginx.conf:

    user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 768;
}

http {

    client_max_body_size 24M;

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

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

    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_types text/plain text/css text/xml application/json application/javascript application/xml+rss application/atom+xml image/svg+xml;

    fastcgi_cache_path /etc/nginx-cache levels=1:2 keys_zone=microcache:5m max_size=1000m;
    log_format cache '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $upstream_cache_status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';

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

Ниже приведен файл из каталога с поддержкой сайтов:

    server {
    root /var/www/vhosts/www.example.com.cn/public_html;
    index index.php index.html index.htm;
    server_name www.example.com.cn;
    access_log  off;
    error_log /var/www/vhosts/www.example.com.cn/log/www.example.com.cn.error.log;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
    location ~ /\.ht {
            deny all;
    }
    location ~ \..*/.*\.php$ {
        return 403;
    }
    location ~ ^/sites/.*/private/ {
        return 403;
    }
    location ~ ^/sites/[^/]+/files/.*\.php$ {
        deny all;
    }
    location ~ (^|/)\. {
        return 403;
    }
    location / {
        try_files $uri /index.php?$query_string; # For Drupal >= 7
    }
    location @rewrite {
        rewrite ^/(.*)$ /index.php?q=$1;
    }
    location ~ \.php$ {
        # Setup var defaults
        set $no_cache "";
        # If non GET/HEAD, don't cache & mark user as uncacheable for 1 second via cookie
        if ($request_method !~ ^(GET|HEAD)$) {
            set $no_cache "1";
        }
        # Drop no cache cookie if need be
        # (for some reason, add_header fails if included in prior if-block)
        if ($no_cache = "1") {
            add_header Set-Cookie "_mcnc=1; Max-Age=2; Path=/";
            add_header X-Microcachable "0";
        }
        # Bypass cache if no-cache cookie is set
        if ($http_cookie ~* "_mcnc") {
                    set $no_cache "1";
        }
        # Bypass cache if flag is set
        fastcgi_no_cache $no_cache;
        #fastcgi_cache_bypass $no_cache;
        fastcgi_cache microcache;
        fastcgi_cache_key $server_name|$request_uri;
        fastcgi_cache_valid 404 30m;
        fastcgi_cache_valid 200 301 302 10m;
        fastcgi_max_temp_file_size 1M;
        fastcgi_cache_use_stale updating;
        fastcgi_pass_header Set-Cookie;
        fastcgi_pass_header Cookie;
        fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        #proxy_cache_use_stale updating error timeout http_500 http_502 http_503 http_504;
        fastcgi_cache_revalidate on;
        #fastcgi_cache_background_update on;

        fastcgi_param  PATH_INFO          $fastcgi_path_info;
        #fastcgi_param  PATH_TRANSLATED    $document_root$fastcgi_path_info;
        include fastcgi_params;

        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }
    location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
        try_files $uri @rewrite;
    }
    location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
        try_files $uri /index.php?$query_string;
    }
    location ~* \.(jpg|js|css|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|pdf|woff|woff2|ttf)$ {
        try_files $uri @rewrite;
        expires max;
        log_not_found off;
        access_log off;
        add_header 'Access-Control-Allow-Origin' '*';
    }
    location  ~ ^/sites/default/files/(?:css|js) {
        gzip_static on;
        access_log off;
        expires max;
    }
}
...