Nginx ayar dosyanizdaki asagidaki alani bulun:
location / {
......
}
Sonrasinda asagidaki kod blogunu yerine yapitirin:
set $cache_ismi $request_uri;
#
# asagidaki islemler icin cache devre disi birakilir
#
# POST istegi gelirse cache ozelligini devre disi birakiriz.
if ($request_method = POST) {
set $cache_ismi 'cache alma';
}
if ($query_string != "") {
set $cache_ismi 'cache alma';
}
# Asagidaki parametrelere uyan url yapisi gelirse cache devre disi birakilir.
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_ismi 'cache alma';
}
# giris yapmis kullanicilar ve son yorumcular icin cache iptal ederiz.
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp_postpass|wordpress_logged_in") {
set $cache_ismi 'cache alma';
}
if ($arg_s != "") { set $cache_ismi 'cache alma'; } # arama sorgulari
if ($arg_p != "") { set $cache_ismi 'cache alma'; } # p=1 seklindeki baglantilar icin.
if ($arg_amp != "") { set $cache_ismi 'cache alma'; } # amp test
if ($arg_preview = "true") { set $cache_ismi 'cache alma'; } # sayfa yada konu onizleme sayfasi
if ($arg_ao_noptimize != "") { set $cache_ismi 'cache alma'; } # Autoptimize eklentisi icin
#
# Cache devredisi birakma sonu
#
set $cihaz "Kuaza Nginx+WP-super-cache: Masaustu cache yada Orjinal";
set $cachedosyasi "/wp-content/cache/supercache/$http_host/$cache_ismi/index-https.html";
#if (-f $document_root/wp-content/cache/supercache/$http_host/$cache_ismi/index-https.html) {
# set $cihaz "Kuaza Nginx+WP-super-cache: Masaustu cache";
#}
if ($http_user_agent ~* "2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800|iPad") { set $cihaz "Kuaza Nginx+WP-super-cache: Mobil cache"; set $cachedosyasi "/wp-content/cache/supercache/$http_host/$cache_ismi/index-https-mobile.html"; }
# uncomment the following if deemed fit
if ($http_user_agent ~* "w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-|ipad") { set $cihaz "Kuaza Nginx+WP-super-cache: Mobil cache"; set $cachedosyasi "/wp-content/cache/supercache/$http_host/$cache_ismi/index-https-mobile.html"; }
# kontrol duzeni: (1) cachedosyasi, (2) normal url, (3) php
location / {
add_header "X-Cache" "HIT - $cihaz $upstream_cache_status";
try_files $cachedosyasi $uri $uri/ /index.php?$args;
}
Sonrasinda nginx e restart atarak ayarlari aktif edelim:
nginx -t && service nginx restart
Kontrol etmek icin sitenizin header bilgilerini buradaki siteye girerek kontrol edebilirsiniz: https://www.webconfs.com/http-header-check.php
Yazdigim herseyi paylasmaya usendim, Kaynak konuya girerek detaylari okuyabilirsiniz.
Detaylar: https://kuaza.com/wordpress-eklentileri/nginx-icin-wp-super-cache-ayarlari-masaustu-ve-mobil-cache-uyumlu