Как правильно сконфигурировать Nginx + Apache + W3 total cache?

Добрый день!
на сервере с ISP-панелью установлен nginx перед apache. Сайт работает на Wordpress с плагином кэширования (кэш браузера и кэш на стороне сервера). Данный плагин генерит конфигурацию для nginx, которую нужно грамотно вставить в мою конфигурацию. Помогите, плз. Весь интернет облазил, подходящего решения не нашел.
текущая конфигурация /etc/nginx/vhosts/user/mysite.ru.conf:
#user 'user' virtual host 'mysite.ru' configuration file
server {
    server_name mysite.ru www.mysite.ru;
    charset UTF-8;
    disable_symlinks if_not_owner from=$root_path;
    index index.html index.php;
    root $root_path;
    set $root_path /var/www/user/data/www/mysite.ru;
    access_log /var/www/httpd-logs/mysite.ru.access.log ;
    #error_log /var/www/httpd-logs/mysite.ru.error.log notice;
    error_log /var/www/httpd-logs/mysite.ru.error.log notice;
    include /etc/nginx/vhosts-includes/*.conf;
    location / {
        location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
            try_files $uri $uri/ @fallback;
        }
        location / {
            try_files /does_not_exists @fallback;
        }
        location ~ [^/]\.ph(p\d*|tml)$ {
            try_files /does_not_exists @fallback;
        }
                location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
                        try_files $uri $uri/ @fallback;
                }
    }
    location @fallback {
        error_log /dev/null crit;
        proxy_pass http://127.0.0.1:8080;
        proxy_redirect http://127.0.0.1:8080 /;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        access_log off ;
    }
    ssi on;
    listen server_IP:80 default_server;
}


Конфигурация W3 Total cache для вставки (насколько она вообще корректна? я читал, что лучше использовать директиву try_files вместо if):
# BEGIN W3TC Page Cache cache
location ~ /wp-content/cache/page_enhanced.*html$ {
    expires modified 86400s;
    add_header X-Powered-By "W3 Total Cache/0.9.4.1";
    add_header Vary "Accept-Encoding, Cookie";
    add_header Pragma "public";
    add_header Cache-Control "max-age=86400, public";
}
location ~ /wp-content/cache/page_enhanced.*gzip$ {
    gzip off;
    types {}
    default_type text/html;
    expires modified 86400s;
    add_header X-Powered-By "W3 Total Cache/0.9.4.1";
    add_header Vary "Accept-Encoding, Cookie";
    add_header Pragma "public";
    add_header Cache-Control "max-age=86400, public";
    add_header Content-Encoding gzip;
}
# END W3TC Page Cache cache
# BEGIN W3TC Browser Cache
gzip on;
gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
location ~ .(css|htc|less|js|js2|js3|js4)$ {
    expires 31536000s;
    add_header Pragma "public";
    add_header Cache-Control "max-age=31536000, public";
    add_header X-Powered-By "W3 Total Cache/0.9.4.1";
}
location ~ .(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$ {
    expires 86400s;
    add_header Pragma "public";
    add_header Cache-Control "max-age=86400, public";
    add_header X-Powered-By "W3 Total Cache/0.9.4.1";
}
location ~ .(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|woff|xla|xls|xlsx|xlt|xlw|zip)$ {
    expires 31536000s;
    add_header Pragma "public";
    add_header Cache-Control "max-age=31536000, public";
    add_header X-Powered-By "W3 Total Cache/0.9.4.1";
}
# END W3TC Browser Cache
# BEGIN W3TC Page Cache core
set $w3tc_rewrite 1;
if ($request_method = POST) {
    set $w3tc_rewrite 0;
}
if ($query_string != "") {
    set $w3tc_rewrite 0;
}
if ($http_cookie ~* "(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle)") {
    set $w3tc_rewrite 0;
}
if ($http_cookie ~* "(w3tc_preview)") {
    set $w3tc_rewrite _preview;
}
set $w3tc_enc "";
if ($http_accept_encoding ~ gzip) {
    set $w3tc_enc _gzip;
}
set $w3tc_ext "";
if (-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_rewrite.html$w3tc_enc") {
    set $w3tc_ext .html;
}
if (-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_rewrite.xml$w3tc_enc") {
    set $w3tc_ext .xml;
}
if ($w3tc_ext = "") {
  set $w3tc_rewrite 0;
}
if ($w3tc_rewrite = 1) {
    rewrite .* "/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_rewrite$w3tc_ext$w3tc_enc" last;
}
# END W3TC Page Cache core
  • Вопрос задан
  • 800 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы