Support » Plugin: W3 Total Cache » Compatibility with WordPress Behind a Reverse Proxy

  • Resolved dstein64


    The WordPress website ( describes a way to configure SSL for an installation hosted behind a reverse proxy that provides SSL. The following is added to wp-config.php:

    if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')

    and in nginx, the following line is added to the secure server block:
    proxy_set_header X-Forwarded-Proto https;

    For this config to work with W3 Total Cache, I have added the following to my nginx config,

    if ($http_x_forwarded_proto = https) {
        set $w3tc_ssl _ssl;

    I have added this below:

    set $w3tc_ssl "";
    if ($scheme = https) {
        set $w3tc_ssl _ssl;

    Here’s the code that would likely have to be added to PgCacheAdmin.php (at around line 978) in order to support this functionality:

    if ($this->_config->get_boolean('pgcache.cache.ssl')) {
        $rules .= "if (\$http_x_forwarded_proto = https) {\n";
        $rules .= "    set \$w3tc_ssl _ssl;\n";
        $rules .= "}\n";

    I could not figure out the appropriate way to submit a pull request, so I’m posting this here.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Frederick Townes


    The latest release improved has proxy support. Please give me your feedback.

    I updated to the latest version. Upon updating, I received http errors (404 and 500 I think) when visiting my site. My nginx config was updated correctly.

    However, after deleting the W3 Total Cache nginx rules and switching from “Disk: Enhanced” to “Disk: Basic” page cache method, everything worked fine. Accessing my site via https, which is proxy passed to http, worked fine.

    I am not sure exactly what the initial problem was, but it may have to do with other settings in my nginx config. I’d be glad to look further into the problem if you’re interested, but I imagine it was specific to me, and is not causing any problem since “Disk: Basic” is giving me similar performance to what I had before the update.

    Plugin Contributor Frederick Townes


    Disk basic is not going to be faster. If you can submit a bug submission form from the support tab of the plugin that is the best path forward.

    The latest update ( made my blog start working again, even with “Disk: Enhanced” caching and the updated nginx rules. However, my homepage, still returned a 400 error. My blog is served from the /blog/ subdirectory of my site, and my homepage is served from /.

    It appeared that the W3TC nginx rules were applying a rewrite, so I added the following, which fixed my problem:

    if ($request_uri !~ ^\/blog\/) {
       set $w3tc_rewrite 0;

    Anyhow, the proxy issues are seemingly resolved, so I am marking this topic as resolved. Thanks.

    I suppose that my new issue is separate, or possibly a feature request if W3TC “Disk: Enhanced” caching doesn’t support blogs hosted from a subdirectory.

    Two mistakes in my last post:

    I meant 404 error, not a 400 error. This was returned from nginx.

    Here is the code block (does not include back slashes):

    if ($request_uri !~ ^/blog/) {
       set $w3tc_rewrite 0;

    Plugin Contributor Frederick Townes


    Ok, thanks.

    I have encountered a simlar situation with my hosting provider who terminates the SSL connection at a load balancer/reverse proxy. Thus the inbound WordPress connection is always HTTP and never HTTPS. With default configurations, I was getting errors in HTTPS pages simply because W3TC was unable to recognise that it should issue URLS for the content that started https:// rather than http://

    One solution would be to always insist on HTTPS, but that does seem wasteful. Another would be to extend the admin GUI to allow users to configure $_SERVER keys/values which distinguish HTTP and HTTPS.

    In my particular case, the reverse proxy added

    so I was able to simply add this test into the w3_is_https() function to make sure that the content URLs matched the actual end-user connection type

    Hi Frederick

    I am using W3 total cache for my wordpress site. I am using amazon elasti cache with the plugin. How can we detect if page is loading from the server or from cache? i have enabled page cache ,object cache, database cache and minify. where can i find those cached objects on my server?

    Thanks in advance…

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Compatibility with WordPress Behind a Reverse Proxy’ is closed to new replies.