Discover Centmin Mod today
Register Now

Wordpress Configure Redis page cache to bypass specific urls

Discussion in 'Blogs & CMS usage' started by savvasha, Nov 30, 2018.

  1. savvasha

    savvasha New Member

    6
    0
    1
    Nov 30, 2018
    Ratings:
    +0
    Local Time:
    8:56 AM
    Nginx 1.15.x
    MariaDB 10.1.x
    Well, I am using a download manager plugin to share some pdf files from my site.
    The problem is that when someone tries to download a file the url used is something like domain.com/download/?down=23 which is served through Redis cache and the Nginx Timestamp is added at the source of the pdf!

    Is there a way to bypass all urls with ?down= variable from redis cache?

    I am using:
    123.09beta01 (latest)
    PHP 7.2.12
    nginx 1.15.6


    Sorry for my bad english :)

    Thanks,
    Savvas
     
  2. eva2000

    eva2000 Administrator Staff Member

    37,227
    8,133
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,521
    Local Time:
    4:56 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    That's an interesting problem to have :)

    Is /download page itself a valid page ? if not you can exclude cache from /download/* ???

    If so you could do similar custom bypass as outlined at Wordpress - WP Super Cache, KeyCDN Cache Enabler, Redis Cache User Agent Bypass for Wordpress just for url and not user agent

    For Redis caching of Wordpress at Nginx level outlined at community.centminmod.com/posts/18828/, in /usr/local/nginx/conf/wpincludes/newdomain.com/rediscache_newdomain.com.conf include file add an extra entry to bypass cache on url containing /download or ?/down=
    Code (Text):
    if ($request_uri ~* "/download/|\?down=") {
      set $skip_cache 1;
    }
    

    or if just ?down=
    Code (Text):
    if ($request_uri ~* "\?down=") {
      set $skip_cache 1;
    }
    

    restart nginx
    Code (Text):
    ngxrestart
    
     
  3. savvasha

    savvasha New Member

    6
    0
    1
    Nov 30, 2018
    Ratings:
    +0
    Local Time:
    8:56 AM
    Nginx 1.15.x
    MariaDB 10.1.x
    Hi eva2000,

    Unfortunately your solution is not working :(

    My actual url format is something like this:
    domain.com/download/file-name/?wpdmdl=xxxxxxx

    So I added the following code :
    Code:
    # Don't use the cache for download links
    if ($request_uri ~* "\?wpdmdl=") {
      set $skip_cache 1;
    }
    but it keeps adding
    Code:
    <!--Cached using Nginx-Helper on 2018-11-30 07:05:48. It took 55 queries executed in 0,109 seconds.-->
    <!--Visit http://wordpress.org/extend/plugins/nginx-helper/faq/ for more details-->
    at the end of pdf files
     
  4. eva2000

    eva2000 Administrator Staff Member

    37,227
    8,133
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,521
    Local Time:
    4:56 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    oh might need to restart php-fpm + nginx services
    Code (Text):
    nprestart
    
     
  5. savvasha

    savvasha New Member

    6
    0
    1
    Nov 30, 2018
    Ratings:
    +0
    Local Time:
    8:56 AM
    Nginx 1.15.x
    MariaDB 10.1.x
    Unfortunately no joy...
    Code:
    <!--Cached using Nginx-Helper on 2018-11-30 10:28:11. It took 54 queries executed in 0,124 seconds.-->
    <!--Visit http://wordpress.org/extend/plugins/nginx-helper/faq/ for more details-->
     
  6. eva2000

    eva2000 Administrator Staff Member

    37,227
    8,133
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,521
    Local Time:
    4:56 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    what if you exclude /download urls too
    Code (Text):
    if ($request_uri ~* "/download/|\?wpdmdl=") {
      set $skip_cache 1;
    }
    
     
  7. savvasha

    savvasha New Member

    6
    0
    1
    Nov 30, 2018
    Ratings:
    +0
    Local Time:
    8:56 AM
    Nginx 1.15.x
    MariaDB 10.1.x
    Still not working. Maybe the problem is in Nginx-Helper plugin?
     
  8. eva2000

    eva2000 Administrator Staff Member

    37,227
    8,133
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,521
    Local Time:
    4:56 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    did you add any other wordpress plugins after install ? i.e. like a redis object cache plugin ? that could maybe mess with saving nginx-helper settings.
     
  9. savvasha

    savvasha New Member

    6
    0
    1
    Nov 30, 2018
    Ratings:
    +0
    Local Time:
    8:56 AM
    Nginx 1.15.x
    MariaDB 10.1.x
    Hi there eva2000,

    Sorry for the long delay on reply :)

    After some more in depth investigation, it seems that when someone wants to download something from my website and the user is using an Apple Device (Mac or iPhone or iPad), the file is not dowloading completely. It seems to stop downloading at 99% and gives an error "The network connection was lost".

    I try to figure out what the exact problem was and I did the following:
    I create a new VPS at digitalocean ($5) and install Centmimod 123.09beta. I then create a website through menu 22 and select the 2nd option (Redis Nginx Level Caching). I then migrate my live site, to this new testing host. So I have the same plugins in both sites! In my Original Site, the files are not downloaded correctly in Apple Devices, but in my Testing Site everything is working just perfect!

    So the problem doesnt seem to be at the cache mechanism after all :)

    The question is, how can I check what is the difference between the configuration of these sites? What files should I check?

    Thanks,
    Savvas
     
  10. eva2000

    eva2000 Administrator Staff Member

    37,227
    8,133
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,521
    Local Time:
    4:56 PM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    check the nginx site domain vhost config file differences first for /usr/local/nginx/conf/conf.d/yourdomain.com.conf or yourdomain.com.ssl.conf. You can use Diff Checker to compare 2 files or a local file compare too i.e. I use beyondcompare

    Or you can just move everything to the working VPS :)
     
..