WordPress.org

Ready to get started?Download WordPress

Forums

W3 Total Cache
[resolved] Compatibility with WordPress Behind a Reverse Proxy (9 posts)

  1. dstein64
    Member
    Posted 1 year ago #

    The WordPress website (http://codex.wordpress.org/Administration_Over_SSL) 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')
           $_SERVER['HTTPS']='on';

    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.

    http://wordpress.org/extend/plugins/w3-total-cache/

  2. Frederick Townes
    Member
    Plugin Author

    Posted 1 year ago #

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

  3. dstein64
    Member
    Posted 1 year ago #

    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.

  4. Frederick Townes
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  5. dstein64
    Member
    Posted 1 year ago #

    The latest update (0.9.2.7) 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.

  6. dstein64
    Member
    Posted 1 year ago #

    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;
    }
  7. Frederick Townes
    Member
    Plugin Author

    Posted 1 year ago #

    Ok, thanks.

  8. kiisu
    Member
    Posted 1 year ago #

    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
    HTTP_X_FORWARDED_SSL 1

    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

  9. peshkarkiran
    Member
    Posted 11 months ago #

    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...

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic