Simulating User Cache Segmentation in LocalWP

Hey all

I’m dropping a post here as I’ve just spent some time working out how to implement a simulation of WPEngine’s User Cache Segmentation in LocalWP and wanted to share this to help others as it was a bit of a faff.

The way that this works is that WPE uses a cookie called “wpe-us” to create a cached “segment” of your WordPress site. That cookie is handled by their Page Cache layer and translated into the HTTP header HTTP_X_WPENGINE_SEGMENT which can then be used to serve cacheable content to a specific segment of users.

Implementing a simulation of this within LocalWP requires two configuration changes, as follows:

  1. Get the value of the wpe-us cookie and store this in an nginx variable: edit the nginx.conf.hbs file and add the following code inside the http block:

    map $http_cookie $fastcgi_wpe_us {
    default “”;
    “~*wpe-us=(?[^;]+)” “$variable”;
    }

  2. Update the site.conf.hbs file to pass the value of the $fastcgi_wpe_us variable as a fastcgi_param, which PHP reads in it’s $_SERVER block. This line should be added inside the PHP-FPM section:

    fastcgi_param HTTP_X_WPENGINE_SEGMENT $fastcgi_wpe_us;

Once these are in place, save the files and stop and start your site and your wpe-us cookie values will appear in the HTTP_X_WPENGINE_SEGMENT variable as you’d expect.

Hope this helps someone!

Source: https://stackoverflow.com/a/45208334

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.