Join the community today
Become a Member

Wordpress Cache-Enabler Plugin Cache Enabler Plugin best config?

Discussion in 'Blogs & CMS usage' started by rdan, Feb 4, 2020.

  1. rdan

    rdan Well-Known Member

    5,452
    1,418
    113
    May 25, 2014
    Ratings:
    +2,212
    Local Time:
    5:10 PM
    Mainline
    10.2
  2. Carlo

    Carlo New Member

    16
    8
    3
    Apr 19, 2017
    Ratings:
    +14
    Local Time:
    7:10 PM

    I can confirm above works and bypasses php-fpm. I think I know why it wasn't working in the first place. In the code:
    Code:
    # default html file
    set $cache_enabler_uri '${custom_subdir}/wp-content/cache/cache-enabler/${http_host}${cache_uri}index.html';
    
    # webp html file
        if ($http_accept ~* "image/webp") {
            set $cache_enabler_uri '${custom_subdir}/wp-content/cache/cache-enabler/${http_host}${cache_uri}index-webp.html';
        }
    It assumes that if the browser accepts webp, it should serve the webp cached version of the file without checking if the file exists, say in the case I opted not to use separate webp version. The content of the variable $cache_enabler_uri is overwritten by the "if" condition without further check if webp version of html file has been generated.

    I replaced the code by using a different variable for the webp uri:
    Code:
    # webp html file
    if ($http_accept ~* "image/webp") {
        set $cache_enabler_uri_webp '${custom_subdir}/wp-content/cache/cache-enabler/${http_host}${cache_uri}index-webp.html';
    }
    Then on my location block:
    Code:
    try_files $cache_enabler_uri_webp $cache_enabler_uri $uri $uri/ /index.php?$args;
    
    Seems to work even if I enable or disable webp caching. I don't see x-cache-handler: wp
    anymore and files are served even if php-fpm has been stopped.
     
  3. eva2000

    eva2000 Administrator Staff Member

    58,894
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    7:10 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    Very nice, thanks for sharing this. Will give it a test when I have time to see. If others can test too that would be great @rdan @pamamolf @Matt @jcat
     
  4. jcat

    jcat Member

    154
    22
    18
    Jun 21, 2015
    New Jersey
    Ratings:
    +65
    Local Time:
    5:10 AM
    Great find, definitely will be testing :)
     
  5. jcat

    jcat Member

    154
    22
    18
    Jun 21, 2015
    New Jersey
    Ratings:
    +65
    Local Time:
    5:10 AM
    Haven't done any stress testing but I can clearly see that it is indeed bypassing PHP. Was always under the impression this was the case when seeing "x-cache-handler: wp" in the headers.
     
  6. Carlo

    Carlo New Member

    16
    8
    3
    Apr 19, 2017
    Ratings:
    +14
    Local Time:
    7:10 PM
    Played with code a bit more. I wanted to include a response header to indicate files are being served directly by nginx. So I check if the cached files exist then assign the header string "nginx" to a variable:
    Code:
    # default html file
    set $cache_enabler_uri '${custom_subdir}/wp-content/cache/cache-enabler/${http_host}${cache_uri}index.html';
    
    # webp html file
    if ($http_accept ~* "image/webp") {
        set $cache_enabler_uri_webp '${custom_subdir}/wp-content/cache/cache-enabler/${http_host}${cache_uri}index-webp.html';
    }
    
    if (-f $document_root$cache_enabler_uri) {
        set $cache_header "nginx";
    }
    if (-f $document_root$cache_enabler_uri_webp) {
        set $cache_header "nginx";
    }
    Then in the location block:
    Code:
    try_files $cache_enabler_uri_webp $cache_enabler_uri $uri $uri/ $custom_subdir/index.php?$args;
    add_header x-cache-handler $cache_header;
    
    (Note, I was not able to include "$custom_subdir/index.php" in the last "try" argument in my previous post but when I checked KeyCDN documentation it should be there)

    I tested code above and it returns the response header x-cache-handler: nginx if files are served directly by nginx, else it responds with x-cache-handler: wp if served via Wordpress/php. So far my limited tests show its working but it'd be good if gurus in the forum can check code too!
     
  7. ahmed

    ahmed Active Member

    404
    49
    28
    Feb 21, 2017
    Ratings:
    +63
    Local Time:
    11:10 AM
    any final update for that new test, please?
     
  8. eva2000

    eva2000 Administrator Staff Member

    58,894
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    7:10 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
  9. eva2000

    eva2000 Administrator Staff Member

    58,894
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    7:10 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
  10. BamaStangGuy

    BamaStangGuy Active Member

    669
    192
    43
    May 25, 2014
    Ratings:
    +272
    Local Time:
    4:10 AM
    Finally able to get this to work. Happy to ditch wp-rocket for this. Saved money and great performance.
     
  11. eva2000

    eva2000 Administrator Staff Member

    58,894
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    7:10 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    Glad to hear :D
     
  12. omrtozd

    omrtozd New Member

    16
    7
    3
    Feb 16, 2021
    Ratings:
    +11
    Local Time:
    12:10 PM
    Hi, I barely remember that I saw your post about using only Cloudflare for caching or something like that. If you remember the context, can you explain what was it about?