Nginx sunucularda php'ye düşmeden file cache işleminin yapılması

Nginx sunucularda php'ye düşmeden file cache işleminin yapılması

Nginx sunucularda php'ye düşmeden file cache işleminin yapılması. Örneğimizi wordpress'te hazırlanmış bir site için vereceğiz!

server {
    server_name example.com www.example.com;

    access_log   /var/log/nginx/example.com.access.log;
    error_log    /var/log/nginx/example.com.error.log debug;

    root /var/www/example.com/htdocs;
    index index.php;

    set $cache_uri $request_uri;

    # POST varsa cache kullanma
    if ($request_method = POST) {
        set $cache_uri 'null cache';
    }

    # GET varsa cache kullanma
    if ($query_string != "") {
        set $cache_uri 'null cache';
    }

    # Aşağıdakiler için de cache kullanma
    if ($request_uri ~* "(/wp-admin/ | /xmlrpc.php | /wp-(app|cron|login|register|mail).php | wp-.*.php | /feed/ | index.php | wp-comments-popup.php | wp-links-opml.php | wp-locations.php | sitemap(_index)?.xml | [a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
        set $cache_uri 'null cache';
    }   

    # Giriş yapan kullanıcılar için cache kullanma
    if ($http_cookie ~* "comment_author | wordpress_[a-f0-9]+ | wp-postpass | wordpress_logged_in") {
        set $cache_uri 'null cache';
    }

    # Eğer varsa cache dosyalarını kullan, yoksa php'ye git (ve cache dosyası oluştur)
    location / {
        try_files /wp-content/cache/ ... /${host}${cache_uri}_index.html $uri $uri/ /index.php?$args ;
    }

    location ~ ^/wp-content/cache/minify/[^/]+/(.*)$ {
        try_files $uri /wp-content/plugins/w3-total-cache/pub/minify.php?file=$1;
    }    

    # Bu dosyalar için log hatası üretme
    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt  { log_not_found off; access_log off; }

    # Statik dosyaları tarayıcıda cache'le
    location ~* .(ogg|ogv|svg|svgz|eot |otf|woff|mp4|ttf|css |rss|atom|js|jpg|jpeg |gif|png|ico|zip|tgz |gz|rar|bz2| doc|xls |exe|ppt|tar|mid|midi |wav|bmp|rtf)$
    {
        expires max; log_not_found off; access_log off;
    }

    ...
}

PHP'ye düşen sayfalarınızda, sayfa içeriğini oluştururken aynı zamanda cache dosyasını da oluşturmak için PHP Cache hazırlama, sitenizin performansını arttırın bağlantısından yararlanabilirsiniz.

'Nginx sunucularda php'ye düşmeden file cache işleminin yapılması' ile ilgili içerikler

Ubuntu ya da Debian sunucu kurulumunda gerekli komutlar
Ubuntu ya da Debian sunucu kurulumunda gerekli komutlar
PHP Cache hazırlama, sitenizin performansını arttırın
PHP Cache hazırlama, sitenizin performansını arttırın
NGINX'te "502 Bad Gateway" hatası nasıl çözülür?
NGINX'te "502 Bad Gateway" hatası nasıl çözülür?