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

seth2958 nginx-forum at
Mon May 8 05:59:43 UTC 2017

Hi all, new to this awesome community, and would greatly appreciate some
help. I love Nginx but 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 All child pages do
not experience the blank page issue. It only occurs for (However, child pages do sometimes intermittently
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

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:

    ^A^F^@^A^@*^F^@Content-type: text/html; charset=UTF-8^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;

    	access_log   /var/log/nginx/;
    	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 ~*
    		set $skip_cache 1;
    	autoindex off;
            location ~ /purge(/.*) {
                    fastcgi_cache_purge WORDPRESS
            location ~*
    		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$
            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/;

    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_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;
    	# 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:
    #	#
    #	# 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        
    fastcgi_param   SCRIPT_FILENAME             $request_filename;
    fastcgi_param   SCRIPT_NAME             $fastcgi_script_name;
    fastcgi_param   PATH_INFO               $fastcgi_path_info;
    fastcgi_param       PATH_TRANSLATED        
    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 -
    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:
    set $path_info $fastcgi_path_info;
    fastcgi_param PATH_INFO $path_info;

    fastcgi_index index.php;
    include fastcgi.conf;

Posted at Nginx Forum:,274097,274097#msg-274097

More information about the nginx mailing list