Weird blank page cached ONLY for Wordpress homepage URL when using keyword monitoring


#1

Hi all, new to this awesome community, and would greatly appreciate some help. For months I’ve been trying to tackle a very strange issue where fastcgi is caching a blank page when monitoring tools like Monitis or Uptime Robot run keyword-based uptime monitors for the root URL only. In this case the site is http://musikandfilm.com. All child pages do not experience the blank page issue. It only occurs for http://musikandfilm.com. (However, child pages do sometimes get blank pages cached if I leave off the “/” at the end of the URL field in my monitor settings, so I think this may have something to do with the issue.)

When I delete the cached page and visit the homepage in my browser, I see fastcgi cache the page correctly. But when I delete the cached page and allow the monitors to hit the site first, a blank home page is cached that looks like the example below, even though I get a 200 response. I believe that the Monitors are requesting the homepage in a certain way that is causing fastcgi to cache the page incorrectly, but I don’t know exactly what’s happening. Here’s an example of what’s cached:

`^C^@^@^@^@^@^@^@<88>o^OY^@^@^@^@ÿÿÿÿÿÿÿÿxa^OY^@^@^@^@C\R^N^@^@¯^@á^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
KEY: httpGETmusikandfilm.com/
^A^F^@^A^@*^F^@Content-type: text/html; charset=UTF-8^M
^M`

And that’s it, there’s no body after this point as there would be if correctly cached.

I’ve been chasing this problem for so long I will gladly pay someone to fix this. I’m not even joking! I’ve checked my NGINX configs a hundred times at this point and followed all the recommendations from RT, NGINX, and elsewhere for NGINX+Wordpress setups, and I have failed thus far. I’ve spent at least 100 hours researching this, so if anyone is willing to help it would so so appreciated. I’m running Ubuntu 16.04, by the way. I’ll post my NGINX configs below:

sites-available/default config:

`#move next 4 lines to /etc/nginx/nginx.conf if you want to use fastcgi_cache across many sites fastcgi_cache_path /var/www/html/nginx-cache levels=1:2 keys_zone=WORDPRESS:100m inactive=60m; #fastcgi_cache_key “$scheme$request_method$http_host$request_uri”; fastcgi_cache_use_stale error timeout invalid_header http_500; fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

server {
        listen 80;
        listen [::]:80;
        
        server_name musikandfilm.com www.musikandfilm.com;

	access_log   /var/log/nginx/musikandfilm.com.access.log;
	error_log    /var/log/nginx/musikandfilm.error.log;

        root /var/www/html;
        index index.php;

	set $skip_cache 0;


	# POST requests and urls with a query string should always go to PHP
	if ($request_method = POST) {
		set $skip_cache 1;
	}   
	if ($query_string != "") {
		set $skip_cache 1;
	}   

	# Don't cache uris containing the following segments
	if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
		set $skip_cache 1;
	}   

	# Don't use the cache for logged in users or recent commenters
	if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
		set $skip_cache 1;
	}
	
	autoindex off;
 
        location ~ /purge(/.*) {
                fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
        }
 	
	
        location ~* ^.+\.(flv|pdf|avi|mov|mp3|wmv|m4v|webm|aac|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
		expires max;
                log_not_found off;
                access_log off;
        }
 
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
 
        location ~ \.php$ {
		try_files $uri /index.php;
		include fastcgi_params;
		include /etc/nginx/snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                if ($request_method = HEAD) {
	                set $skip_cache 1;
        	}
		fastcgi_cache_bypass $skip_cache;
                fastcgi_no_cache $skip_cache;
		fastcgi_cache WORDPRESS;
                fastcgi_cache_valid 200 60m;
        }
 
        location ~* ^/wp-includes/.*(?<!(js/tinymce/wp-tinymce))\.php$ {
                internal;
        }
 
        location = /favicon.ico {
                log_not_found off;
                access_log off;
        }
 
        location = /robots.txt {
                access_log off;
                log_not_found off;
        }
 
        location = /wp-config.php {
                deny all;
        }
 
        location ~* /(?:uploads|files)/.*\.php$ {
                deny all;
        }
 
        location ~* ^/wp-content/.*\.(txt|md|exe|sh|bak|inc|php|pot|po|mo|log|sql)$ {
                deny all;
        }
 
        location ~ /\.(ht|svn)? {
                deny all;
        }
}`

/etc/nginx/nginx.conf

`user www-data;
worker_processes auto;
worker_rlimit_nofile 100000;
pid /run/nginx.pid;

events {
	worker_connections 4096;
	multi_accept on;
}

http {
	##
	# EasyEngine Settings
	##

	sendfile on;
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout 30;
	types_hash_max_size 2048;

	server_tokens off;
	reset_timedout_connection on;
	# add_header X-Powered-By "EasyEngine";
	# add_header rt-Fastcgi-Cache $upstream_cache_status;

	# Limit Request
	limit_req_status 403;
	limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;

	# Proxy Settings
	# set_real_ip_from	proxy-server-ip;
	# real_ip_header	X-Forwarded-For;

	fastcgi_read_timeout 300;
	client_max_body_size 100m;

	##
	# SSL Settings
	##

	ssl_session_cache shared:SSL:20m;
	ssl_session_timeout 10m;
	ssl_prefer_server_ciphers on;
	ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA;
	ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

	##
	# Basic Settings
	##
	# server_names_hash_bucket_size 64;
	# server_name_in_redirect off;

	include /etc/nginx/mime.types;
	default_type application/octet-stream;

	##
	# Logging Settings
	##

	access_log /var/log/nginx/access.log;
	error_log /var/log/nginx/error.log;

	# Log format Settings
	log_format rt_cache '$remote_addr $upstream_response_time $upstream_cache_status [$time_local] '
	'$http_host "$request" $status $body_bytes_sent '
	'"$http_referer" "$http_user_agent"';

	##
	# Gzip Settings
	##

	gzip on;
	gzip_disable "msie6";

	gzip_vary on;
	gzip_proxied any;
	gzip_comp_level 6;
	gzip_buffers 16 8k;
	gzip_http_version 1.1;
	gzip_types
	    application/atom+xml
	    application/javascript
	    application/json
	    application/rss+xml
	    application/vnd.ms-fontobject
	    application/x-font-ttf
	    application/x-web-app-manifest+json
	    application/xhtml+xml
	    application/xml
	    font/opentype
	    image/svg+xml
	    image/x-icon
	    text/css
	    text/plain
	    text/x-component
	    text/xml
	    text/javascript;
	##
	# Cache Settings
	##
        
	fastcgi_cache_key "$scheme$request_method$http_host$request_uri";
	#add_header Fastcgi-Cache $upstream_cache_status;
	#add_header Fastcgi-method $request_method;

	##
	# Virtual Host Configs
	##

	include /etc/nginx/conf.d/*.conf;
	include /etc/nginx/sites-enabled/*;
}


#mail {
#	# See sample authentication script at:
#	# http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#	# auth_http localhost/auth.php;
#	# pop3_capabilities "TOP" "USER";
#	# imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#	server {
#		listen     localhost:110;
#		protocol   pop3;
#		proxy      on;
#	}
#
#	server {
#		listen     localhost:143;
#		protocol   imap;
#		proxy      on;
#	}
#}`

fastcgi_params

fastcgi_param   QUERY_STRING            $query_string;
fastcgi_param   REQUEST_METHOD          $request_method;
fastcgi_param   REQUEST_SCHEME          $scheme;
fastcgi_param   CONTENT_TYPE            $content_type;
fastcgi_param   CONTENT_LENGTH          $content_length;
fastcgi_param 	HOST 			$host;

#fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;
fastcgi_param   SCRIPT_FILENAME             $request_filename;
fastcgi_param   SCRIPT_NAME             $fastcgi_script_name;
fastcgi_param   PATH_INFO               $fastcgi_path_info;
fastcgi_param       PATH_TRANSLATED         $document_root$fastcgi_path_info;
fastcgi_param   REQUEST_URI             $request_uri;
fastcgi_param   DOCUMENT_URI            $document_uri;
fastcgi_param   DOCUMENT_ROOT           $document_root;
fastcgi_param   SERVER_PROTOCOL         $server_protocol;

fastcgi_param   GATEWAY_INTERFACE       CGI/1.1;
fastcgi_param   SERVER_SOFTWARE         nginx/$nginx_version;

fastcgi_param   REMOTE_ADDR             $remote_addr;
fastcgi_param   REMOTE_PORT             $remote_port;
fastcgi_param   SERVER_ADDR             $server_addr;
fastcgi_param   SERVER_PORT             $server_port;
fastcgi_param   SERVER_NAME             $server_name;

fastcgi_param   HTTPS                   $https;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param   REDIRECT_STATUS         200;

# To fix CGI application vulnerability - https://httpoxy.org
fastcgi_param   HTTP_PROXY      "";

fastcgi-php.conf

# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;

# Check that the PHP script exists before passing it
#try_files $fastcgi_script_name =404;

# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;

fastcgi_index index.php;
include fastcgi.conf;

#2