• Resolved technichdml

    (@technichdml)


    Hi,

    i have a very urgent problem to solve.
    We use AWS Elastic Beanstalk and Loadbalancer together with W3 Total Cache pro.

    Amazon EBS Loadbalancer makes a healthcheck which will request the file /wp.load.php to see if the systems are still healthy.
    When status code http: 200 is returned AWS sees out instances as healthy.

    This is from the NGINX Logfile before i enable Page Cache
    [26/Apr/2022:14:04:53 +0000] “GET /wp-load.php HTTP/1.1” 200 31 “-” “ELB-HealthChecker/2.0” “-”

    Now when i enable the Page Cache within W3 Total cache we get a 301 HTTP Code
    And Amazon Elastic Beanstalk thinks our servers are broken.

    [26/Apr/2022:14:01:11 +0000] “GET /wp-load.php HTTP/1.1” 301 5 “-” “ELB-HealthChecker/2.0” “-”

    Somehow the Page Cache (all other caches work well) is changing that request to a 301 response code.

    How can i avoid that? Is there some setting or anything else?
    Where in the code do i find whats happening?
    can i blacklist that wp-loader.php url or such?

    Please help its really a big deal for us.

    All other caching methods work like a charm.

    Thank you a lot.
    Best Frank

    • This topic was modified 2 years, 7 months ago by technichdml.
    • This topic was modified 2 years, 7 months ago by technichdml.
    • This topic was modified 2 years, 7 months ago by technichdml.
Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @technichdml

    Thank you for reaching out and I am happy to assist you with this.
    Can you please share if you are experiencing any problems on the website or is this just related to the Amazon EBS Loadbalancer health check?
    This is the first time I am seeing this kind of problem-related and Page Caching should not have any effect on the wp-load.php HTTP response.
    Can you please share the website URL and also the Nginx.conf content?
    Do you have any redirect plugins or any redirect rules on Amazon EBS Loadbalancer or nginx.conf?
    Thanks!

    Thread Starter technichdml

    (@technichdml)

    Hi @vmarko

    thank you so far!

    – no problems at the website problem just relates to EBS Loadbalancer failing healthchecks cause of the 301 status code.

    – no redirect plugins , no rewrite rules in nginx except thoose created from your plugin

    – AT EBS Loadbalancer you have to use HTTP thus i have thoose listener and processes:
    https://snipboard.io/HIcKMg.jpg

    – also in wp-config.php its checked if requests comes from ELB or cloudfront. This is needed to make it work.

    /**  Detect if SSL is used. This is required since we are terminating SSL either on CloudFront or on ELB */
    if ((@$_SERVER['HTTP_CLOUDFRONT_FORWARDED_PROTO'] == 'https') OR (@$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) {$_SERVER['HTTPS']='on
    

    Same for me i have no clue why this happens when i activate Page Cache. Makes no sense for me but i debugged it down that far.

    Website URL is https::/hundemarmelade.de

    Nginx.conf:

    `location = /favicon.ico {
    log_not_found off;
    access_log off;
    }

    location / {
    index index.php index.html index.htm;
    try_files $uri $uri/ /index.php?$args;
    #try_files $uri $uri/ /index.php?q=$uri&$args;
    #gzip_static on;
    }

    # rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    # BEGIN W3TC CDN
    location ~ \.(ttf|ttc|otf|eot|woff|woff2|font.css)$ {
    expires 31536000s;
    etag on;
    if_modified_since exact;
    add_header Pragma “public”;
    add_header Cache-Control “public”;
    add_header X-Powered-By “W3 Total Cache/2.2.1”;
    add_header Referrer-Policy “no-referrer-when-downgrade”;
    add_header Access-Control-Allow-Origin “*”;
    }
    # END W3TC CDN
    # BEGIN W3TC Browser Cache
    gzip on;
    gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext text/plain text/xsd text/xsl text/xml image/bmp application/java application/msword application/vnd.ms-fontobject application/x-msdownload image/x-icon application/json application/vnd.ms-access video/webm application/vnd.ms-project application/x-font-otf application/vnd.ms-opentype application/vnd.oasis.opendocument.database application/vnd.oasis.opendocument.chart application/vnd.oasis.opendocument.formula application/vnd.oasis.opendocument.graphics application/vnd.oasis.opendocument.spreadsheet application/vnd.oasis.opendocument.text audio/ogg application/pdf application/vnd.ms-powerpoint image/svg+xml application/x-shockwave-flash image/tiff application/x-font-ttf audio/wav application/vnd.ms-write application/font-woff application/font-woff2 application/vnd.ms-excel;
    location ~ (robots\.txt|[a-z0-9_\-]*sitemap[a-z0-9_\.\-]*\.(xml|xsl|html)(\.gz)?) {
    try_files $uri $uri/ /index.php?$args;
    }
    location ~ \.(css|htc|less|js|js2|js3|js4)$ {
    expires 31536000s;
    etag on;
    if_modified_since exact;
    add_header Pragma “public”;
    add_header Cache-Control “public”;
    add_header X-Powered-By “W3 Total Cache/2.2.1”;
    add_header Referrer-Policy “no-referrer-when-downgrade”;
    }
    location ~ \.(html|htm|rtf|rtx|txt|xsd|xsl|xml)$ {
    expires 3600s;
    etag on;
    if_modified_since exact;
    add_header Pragma “public”;
    add_header Cache-Control “public”;
    add_header X-Powered-By “W3 Total Cache/2.2.1”;
    add_header Referrer-Policy “no-referrer-when-downgrade”;
    }
    location ~ \.(asf|asx|wax|wmv|wmx|avi|avif|avifs|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|webp|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|webm|mpp|_otf|odb|odc|odf|odg|odp|ods|odt|ogg|ogv|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|_ttf|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ {
    expires 31536000s;
    etag on;
    if_modified_since exact;
    add_header Pragma “public”;
    add_header Cache-Control “public”;
    add_header X-Powered-By “W3 Total Cache/2.2.1”;
    add_header Referrer-Policy “no-referrer-when-downgrade”;
    }
    add_header Referrer-Policy “no-referrer-when-downgrade”;
    # END W3TC Browser Cache
    # BEGIN W3TC Page Cache core
    set $w3tc_rewrite 1;
    if ($request_method = POST) {
    set $w3tc_rewrite 0;
    }
    if ($query_string != “”) {
    set $w3tc_rewrite 0;
    }
    if ($http_cookie ~* “(comment_author|wp\-postpass|wordpress_logged_in|wptouch_switch_toggle)”) {
    set $w3tc_rewrite 0;
    }
    set $w3tc_preview “”;
    if ($http_cookie ~* “(w3tc_preview)”) {
    set $w3tc_preview _preview;
    }
    set $w3tc_ssl “”;
    if ($scheme = https) {
    set $w3tc_ssl _ssl;
    }
    if ($http_x_forwarded_proto = ‘https’) {
    set $w3tc_ssl _ssl;
    }
    set $w3tc_enc “”;
    if ($http_accept_encoding ~ gzip) {
    set $w3tc_enc _gzip;
    }
    set $request_uri_noslash $request_uri;
    if ($request_uri ~ “(.*?)(/+)$”) {
    set $request_uri_noslash $1;
    }
    location ~ “.*(?<!php)$” {
    set $memcached_key “$http_host$request_uri_noslash/$w3tc_ssl$w3tc_preview$w3tc_enc”;
    memcached_gzip_flag 65536;
    default_type text/html;
    if ($w3tc_rewrite = 1) {
    memcached_pass 127.0.0.1:11211;
    }
    error_page 404 502 504 = @fallback;
    }
    location @fallback {
    try_files $uri $uri/ $uri.html /index.php?$args;
    }
    # END W3TC Page Cache core

    • This reply was modified 2 years, 7 months ago by technichdml.
    • This reply was modified 2 years, 7 months ago by technichdml.
    • This reply was modified 2 years, 7 months ago by technichdml.
    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @technichdml

    Thank you for yoru feedback.
    Can you please check where those redirect points to?
    Are you using WPMU? If the redirect is to ?repeat=w3tc, this redirect should be issued once under normal conditions.
    wp-content/w3tc-config/blogs.php file is created on that redirect with blog URLs mapping info. and permanent redirect usually caused by an inability to create that file (locked down permissions).
    If my assumptions are correct, you may try to manually delete the blogs.php file and it should be re-created.
    Also, in this case, it can be handled by building a host map by making one test request or it can be a redirect to a canonical hostname – our prevention from building multiple mirrors. Worst case scenario, you may use your own PHP file (not wp one) for checking if such a redirect is legal – meaning you tried to access WP with an invalid URL.

    Whitelisting 301 responses is another solution, however, it seems that Elastic Loadbalancer does not have that solution.

    Thanks!

    Thread Starter technichdml

    (@technichdml)

    Hi @vmarko
    – not using WPMU.
    – there is no wp-content/w3tc-config/blogs.php created

    I made some more testing with enhanced nginx log_format

    log_format main ‘$remote_addr – $remote_user [$time_local] “$host” “$request” ‘
    ‘”$request_method $scheme://$host$request_uri $server_protocol” ‘
    ‘$status $body_bytes_sent “$http_referer” ‘
    ‘”$http_user_agent” “$http_x_forwarded_for” “$sent_http_location”‘;

    Now we see its the HTTPS redirect somehow:

    Without Page cache enabled:

    172.30.0.236 – – [27/Apr/2022:17:44:39 +0000] “172.30.2.193” “GET /wp-load.php HTTP/1.1” “GET https://172.30.2.193/wp-load.php HTTP/1.1” 200 31 “-” “ELB-HealthChecker/2.0” “-” “-”
    172.30.2.92 – – [27/Apr/2022:17:44:40 +0000] “172.30.2.193” “GET /wp-load.php HTTP/1.1” “GET https://172.30.2.193/wp-load.php HTTP/1.1” 200 31 “-” “ELB-HealthChecker/2.0” “-” “-”

    With Page cache enabled:

    `172.30.0.236 – – [27/Apr/2022:17:44:54 +0000] “172.30.2.193” “GET /wp-load.php HTTP/1.1” “GET https://172.30.2.193/wp-load.php HTTP/1.1” 301 5 “-” “ELB-HealthChecker/2.0” “-” “https://hundemarmelade.de/wp-load.php&#8221;
    172.30.2.92 – – [27/Apr/2022:17:44:55 +0000] “172.30.2.193” “GET /wp-load.php HTTP/1.1” “GET https://172.30.2.193/wp-load.php HTTP/1.1” 301 5 “-” “ELB-HealthChecker/2.0” “-” “https://hundemarmelade.de/wp-load.php&#8221;

    So i see we have the 301 redirect here which causes the problem for me. But where does it come from?

    Is it maybe function redirect_on_foreign_domain()
    in wp-content/plugins/w3-total-cache/PgCache_Plugin.php

    I will continue debuging…. Need this be solved else my whole cloud infrastructure does not work as planned ??

    Thank you so much for your help!

    Best Frank

    • This reply was modified 2 years, 6 months ago by technichdml.
    • This reply was modified 2 years, 6 months ago by technichdml.
    Thread Starter technichdml

    (@technichdml)

    ignore that &.#8221; postfix this is just a copy and paste error its hard to format source code pretty well here in this forum

    • This reply was modified 2 years, 6 months ago by technichdml.
    Thread Starter technichdml

    (@technichdml)

    @vmarko

    More debugging and findings

    Looks like i am right with function redirect_on_foreign_domain() causing the redirect and problem in my case.

    As far as i understand:

    That functions takes the WordPress Home URL defined (in my case https://hundemarmelade.de) and compares it with
    the $request host. If the request comes from the AMAZON EBS loadbalancer healthcheck it is not https://hundemarmelade.de but
    for example $request_host :172.30.2.193 as you can see in the nginx log files above.

    The following if conditions in function redirect_on_foreign_domain() will then recognize that the hosts do not match and create the redirect with the URL from get_home_url().

    That also explains why if i call https://hundemarmelade.de/wp-loader.php from my browser the host matches and thus no redirect is created.

    If i put
    if ($_SERVER[‘REQUEST_URI’] == ‘/wp-load.php’) return;
    at first line of the function EBS Loadbalancer reports healthy again and no redirect.

    But that cant be the fix? Also it would be gone everytime i update your plugin.

    Whats the purpose of that function? Have you any idea how to fix this?
    Thanks a lot
    Best Frank

    • This reply was modified 2 years, 6 months ago by technichdml.
    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @technichdml

    Thank you for yoru feedback.
    I’ve consulted with the devs and this is ane expected behavior because you are trying to access the WordPress website by the IP, and not its home domain.
    You can make your own PHP script for a health check, if you want to load wp core there – rewrite host first by $_SERVER['HTTP_HOST'] = 'my-blog-host.com';

    Thanks!

    Thread Starter technichdml

    (@technichdml)

    Hi @vmarko

    i do not agree. It may be expected behavior for 99% of your customers but it makes your Page Cache practically unusable for people with an AWS Loadbalancer in front.

    Its not ME requesting the WordPress website by IP its AWS Loadbalancer architecture, that is how its designed by Amazon.
    It uses http requests after the LB to call the specific node backend IPs.

    If you have multiple nodes the loadbalancer looks which node is still healthy and only forwards requests to the healthy notes. So in this case everything would fail.

    How else they should check if a specific instance is still available for requests when not by the IP of the instance?

    They cant use the main domain they have to call each instance over HTTP by IP.

    With the 301 redirect to Domainname it destroys the whole AWS Loadbalancer architecture, and i still do not got the reason. If i don’t want my Website to be called by IP i can still disallow that on webserver settings.

    Of course i can write my own healthcheck but normally the purpose for a healthcheck is to check if the site still renders, the site as customers would request it.

    Normally you would even use / (homepage) for healthchecks of a website to see if the mainpage does not report any error. My wp-load.php was already a workaround.

    So IMHO you could/ should make that some kind of feature (Disable HOST check, Blacklist URLs, Healthcheck Whitelist or whatsoever)

    I have a workaround for me now even if its not the best one.
    So i am fine.

    Thanks a lot for your support. You may close that ticket now

    Best
    Frank

    • This reply was modified 2 years, 6 months ago by technichdml.
    • This reply was modified 2 years, 6 months ago by technichdml.
    • This reply was modified 2 years, 6 months ago by technichdml.
    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @technichdml

    Thank you for your feedback and sorry for the late reply.
    The problem is that health check doesn’t only checks if the site still renders, it checks internal HTTP request of internal IP renders something similar to the site”, and this is not equal.
    It’s a bit of a grey zone, and while it appears valid – there are several severe reasons why it’s not like for SEO, properties of WP behavior for similar requests for WPMU, and of course, caching
    The only workaround and the solution for this are in my previous post.

    Once again, thank you for your question and I hope I was able to help and clarify this.

    Thanks!

    Thread Starter technichdml

    (@technichdml)

    Hi @vmarko ,

    latest Update of your plugin killed my hotfix as expected.

    Can you and your dev team please consider to make
    the check in redirect_on_foreign_domain() an option?
    Remember my hotfix was if ($_SERVER[‘REQUEST_URI’] == ‘/wp-load.php’) return; in 1st Line one of that function.

    So if a user says “false” in backend that this host check is ignored?

    For customers behind a AWS loadbalancer like me?
    Option should be to choose if you want to have a
    redirect_on_foreign_domain or not.

    Thank you for your time
    Best Frank

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘AWS Elastic Loadbalancer Fails when Page Cache enabled’ is closed to new replies.