Quick question on NGINX cache

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Quick question on NGINX cache

Alex Evonosky
This should be pretty simple as I really cannot find a good answer on:


Running Wordpress with the default permalinks (?page_id=xxx)

On NGINX conf, I tried:

location / {
try_files $uri $uri/ /$args /index.php?$args;
}

And the main page caches OK, but any page the resides on the "?page_id" is not getting cached.  Is there more to the "try_files" that needs applied for caching of these permalinks?


Thank You,
Alex

 

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Quick question on NGINX cache

J.R.
> And the main page caches OK, but any page the resides on the "?page_id" is
> not getting cached.  Is there more to the "try_files" that needs applied
> for caching of these permalinks?

Can you be more specific? Which "cache"? Browser cache? Nginx content
cache? try_files has nothing to do with caching...

Either way, you need to check your headers to ensure that they allow
caching for said pages. Also if any cookies are being sent then nginx
won't cache the page.
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Quick question on NGINX cache

Alex Evonosky
"Can you be more specific? Which "cache"? Browser cache? Nginx content
cache? try_files has nothing to do with caching..."


Nginx content cache


"Either way, you need to check your headers to ensure that they allow
caching for said pages. Also if any cookies are being sent then nginx
won't cache the page."


I looked at the headers using CURL..  

The issue seems this:


The request hits NGINX and the backend server(s) for Wordpress are cached just fine from just the FQDN --- example.com

however, if I try to go to say, example.com/?page_id=1234, the headers do not show NGINX anymore, as only the servers for Wordpress show up; Almost like a 
cache punch-hole.


===== proxy.conf ====

proxy_cache_path /tmp/cache keys_zone=my_cache:10m max_size=10m inactive=60m;

#proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header X-Cache-Status $upstream_cache_status;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;



==== nginx.conf ====

http {
        upstream example.com {
        least_conn;
        server 10.10.10.138:8999;
        server 10.10.10.84:8999;
        }

server {
listen 82;
location / {
try_files $uri $uri/ /$args /index.php?$args;
proxy_cache my_cache;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
proxy_cache_background_update on;
proxy_pass http://example.com;
proxy_cache_valid any 60m;
proxy_cache_methods GET HEAD POST;
proxy_http_version 1.1;
proxy_set_header Connection keep-alive;
proxy_ignore_headers Cache-Control Expires Set-Cookie;
      }
}

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

gzip on;
gzip_disable "msie6";

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

}





Thank you,
Alex




On Sat, May 23, 2020 at 8:43 AM J.R. <[hidden email]> wrote:
> And the main page caches OK, but any page the resides on the "?page_id" is
> not getting cached.  Is there more to the "try_files" that needs applied
> for caching of these permalinks?

Can you be more specific? Which "cache"? Browser cache? Nginx content
cache? try_files has nothing to do with caching...

Either way, you need to check your headers to ensure that they allow
caching for said pages. Also if any cookies are being sent then nginx
won't cache the page.
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Quick question on NGINX cache

Alex Evonosky
Disregard, found the issue.

thank you.

On Sat, May 23, 2020 at 4:18 PM Alex Evonosky <[hidden email]> wrote:
"Can you be more specific? Which "cache"? Browser cache? Nginx content
cache? try_files has nothing to do with caching..."


Nginx content cache


"Either way, you need to check your headers to ensure that they allow
caching for said pages. Also if any cookies are being sent then nginx
won't cache the page."


I looked at the headers using CURL..  

The issue seems this:


The request hits NGINX and the backend server(s) for Wordpress are cached just fine from just the FQDN --- example.com

however, if I try to go to say, example.com/?page_id=1234, the headers do not show NGINX anymore, as only the servers for Wordpress show up; Almost like a 
cache punch-hole.


===== proxy.conf ====

proxy_cache_path /tmp/cache keys_zone=my_cache:10m max_size=10m inactive=60m;

#proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header X-Cache-Status $upstream_cache_status;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;



==== nginx.conf ====

http {
        upstream example.com {
        least_conn;
        server 10.10.10.138:8999;
        server 10.10.10.84:8999;
        }

server {
listen 82;
location / {
try_files $uri $uri/ /$args /index.php?$args;
proxy_cache my_cache;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
proxy_cache_background_update on;
proxy_pass http://example.com;
proxy_cache_valid any 60m;
proxy_cache_methods GET HEAD POST;
proxy_http_version 1.1;
proxy_set_header Connection keep-alive;
proxy_ignore_headers Cache-Control Expires Set-Cookie;
      }
}

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

gzip on;
gzip_disable "msie6";

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

}





Thank you,
Alex




On Sat, May 23, 2020 at 8:43 AM J.R. <[hidden email]> wrote:
> And the main page caches OK, but any page the resides on the "?page_id" is
> not getting cached.  Is there more to the "try_files" that needs applied
> for caching of these permalinks?

Can you be more specific? Which "cache"? Browser cache? Nginx content
cache? try_files has nothing to do with caching...

Either way, you need to check your headers to ensure that they allow
caching for said pages. Also if any cookies are being sent then nginx
won't cache the page.
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Quick question on NGINX cache

Jore

Hi Alex/all,

How did you fix?

I've got a very similar issue.

nginx running Wordpress with the Hypercache plugin but only the homepage is cached, other pages "miss" according to page headers.

Thanks,
Jore


On 24/5/20 7:04 am, Alex Evonosky wrote:
Disregard, found the issue.

thank you.

On Sat, May 23, 2020 at 4:18 PM Alex Evonosky <[hidden email]> wrote:
"Can you be more specific? Which "cache"? Browser cache? Nginx content
cache? try_files has nothing to do with caching..."


Nginx content cache


"Either way, you need to check your headers to ensure that they allow
caching for said pages. Also if any cookies are being sent then nginx
won't cache the page."


I looked at the headers using CURL..  

The issue seems this:


The request hits NGINX and the backend server(s) for Wordpress are cached just fine from just the FQDN --- example.com

however, if I try to go to say, example.com/?page_id=1234, the headers do not show NGINX anymore, as only the servers for Wordpress show up; Almost like a 
cache punch-hole.


===== proxy.conf ====

proxy_cache_path /tmp/cache keys_zone=my_cache:10m max_size=10m inactive=60m;

#proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header X-Cache-Status $upstream_cache_status;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;



==== nginx.conf ====

http {
        upstream example.com {
        least_conn;
        server 10.10.10.138:8999;
        server 10.10.10.84:8999;
        }

server {
listen 82;
location / {
try_files $uri $uri/ /$args /index.php?$args;
proxy_cache my_cache;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
proxy_cache_background_update on;
proxy_pass http://example.com;
proxy_cache_valid any 60m;
proxy_cache_methods GET HEAD POST;
proxy_http_version 1.1;
proxy_set_header Connection keep-alive;
proxy_ignore_headers Cache-Control Expires Set-Cookie;
      }
}

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

gzip on;
gzip_disable "msie6";

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

}





Thank you,
Alex




On Sat, May 23, 2020 at 8:43 AM J.R. <[hidden email]> wrote:
> And the main page caches OK, but any page the resides on the "?page_id" is
> not getting cached.  Is there more to the "try_files" that needs applied
> for caching of these permalinks?

Can you be more specific? Which "cache"? Browser cache? Nginx content
cache? try_files has nothing to do with caching...

Either way, you need to check your headers to ensure that they allow
caching for said pages. Also if any cookies are being sent then nginx
won't cache the page.
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

RE: Re: Quick question on NGINX cache

7149144120
In reply to this post by Alex Evonosky
Iol

  -----Original Message-----
  From: <[hidden email]>
  Sent: Sat, 23 May 2020 16:18:33 -0400
  To: [hidden email]
 Subject: Re: Quick question on NGINX cache

>"Can you be more specific? Which "cache"? Browser cache? Nginx content
>cache? try_files has nothing to do with caching..."
>
>
>Nginx content cache
>
>
>"Either way, you need to

==================================================================
This mobile text message is brought to you by AT&T
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Quick question on NGINX cache

Alex Evonosky
In reply to this post by Jore
Jore-

I applied the proxy_hide_header for no-cache headers to NGINX can process it and cache it.

On Sat, May 23, 2020 at 5:17 PM Jore <[hidden email]> wrote:

Hi Alex/all,

How did you fix?

I've got a very similar issue.

nginx running Wordpress with the Hypercache plugin but only the homepage is cached, other pages "miss" according to page headers.

Thanks,
Jore


On 24/5/20 7:04 am, Alex Evonosky wrote:
Disregard, found the issue.

thank you.

On Sat, May 23, 2020 at 4:18 PM Alex Evonosky <[hidden email]> wrote:
"Can you be more specific? Which "cache"? Browser cache? Nginx content
cache? try_files has nothing to do with caching..."


Nginx content cache


"Either way, you need to check your headers to ensure that they allow
caching for said pages. Also if any cookies are being sent then nginx
won't cache the page."


I looked at the headers using CURL..  

The issue seems this:


The request hits NGINX and the backend server(s) for Wordpress are cached just fine from just the FQDN --- example.com

however, if I try to go to say, example.com/?page_id=1234, the headers do not show NGINX anymore, as only the servers for Wordpress show up; Almost like a 
cache punch-hole.


===== proxy.conf ====

proxy_cache_path /tmp/cache keys_zone=my_cache:10m max_size=10m inactive=60m;

#proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header X-Cache-Status $upstream_cache_status;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;



==== nginx.conf ====

http {
        upstream example.com {
        least_conn;
        server 10.10.10.138:8999;
        server 10.10.10.84:8999;
        }

server {
listen 82;
location / {
try_files $uri $uri/ /$args /index.php?$args;
proxy_cache my_cache;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
proxy_cache_background_update on;
proxy_pass http://example.com;
proxy_cache_valid any 60m;
proxy_cache_methods GET HEAD POST;
proxy_http_version 1.1;
proxy_set_header Connection keep-alive;
proxy_ignore_headers Cache-Control Expires Set-Cookie;
      }
}

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

gzip on;
gzip_disable "msie6";

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

}





Thank you,
Alex




On Sat, May 23, 2020 at 8:43 AM J.R. <[hidden email]> wrote:
> And the main page caches OK, but any page the resides on the "?page_id" is
> not getting cached.  Is there more to the "try_files" that needs applied
> for caching of these permalinks?

Can you be more specific? Which "cache"? Browser cache? Nginx content
cache? try_files has nothing to do with caching...

Either way, you need to check your headers to ensure that they allow
caching for said pages. Also if any cookies are being sent then nginx
won't cache the page.
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Quick question on NGINX cache

Jore

Hi there,

Thanks for that.

Could you provide an example conf by any chance please, so I can get my head around that?

Thanks!
Jore


On 24/5/20 8:56 am, Alex Evonosky wrote:
Jore-

I applied the proxy_hide_header for no-cache headers to NGINX can process it and cache it.

On Sat, May 23, 2020 at 5:17 PM Jore <[hidden email]> wrote:

Hi Alex/all,

How did you fix?

I've got a very similar issue.

nginx running Wordpress with the Hypercache plugin but only the homepage is cached, other pages "miss" according to page headers.

Thanks,
Jore


On 24/5/20 7:04 am, Alex Evonosky wrote:
Disregard, found the issue.

thank you.

On Sat, May 23, 2020 at 4:18 PM Alex Evonosky <[hidden email]> wrote:
"Can you be more specific? Which "cache"? Browser cache? Nginx content
cache? try_files has nothing to do with caching..."


Nginx content cache


"Either way, you need to check your headers to ensure that they allow
caching for said pages. Also if any cookies are being sent then nginx
won't cache the page."


I looked at the headers using CURL..  

The issue seems this:


The request hits NGINX and the backend server(s) for Wordpress are cached just fine from just the FQDN --- example.com

however, if I try to go to say, example.com/?page_id=1234, the headers do not show NGINX anymore, as only the servers for Wordpress show up; Almost like a 
cache punch-hole.


===== proxy.conf ====

proxy_cache_path /tmp/cache keys_zone=my_cache:10m max_size=10m inactive=60m;

#proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header X-Cache-Status $upstream_cache_status;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;



==== nginx.conf ====

http {
        upstream example.com {
        least_conn;
        server 10.10.10.138:8999;
        server 10.10.10.84:8999;
        }

server {
listen 82;
location / {
try_files $uri $uri/ /$args /index.php?$args;
proxy_cache my_cache;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
proxy_cache_background_update on;
proxy_pass http://example.com;
proxy_cache_valid any 60m;
proxy_cache_methods GET HEAD POST;
proxy_http_version 1.1;
proxy_set_header Connection keep-alive;
proxy_ignore_headers Cache-Control Expires Set-Cookie;
      }
}

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

gzip on;
gzip_disable "msie6";

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

}





Thank you,
Alex




On Sat, May 23, 2020 at 8:43 AM J.R. <[hidden email]> wrote:
> And the main page caches OK, but any page the resides on the "?page_id" is
> not getting cached.  Is there more to the "try_files" that needs applied
> for caching of these permalinks?

Can you be more specific? Which "cache"? Browser cache? Nginx content
cache? try_files has nothing to do with caching...

Either way, you need to check your headers to ensure that they allow
caching for said pages. Also if any cookies are being sent then nginx
won't cache the page.
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Quick question on NGINX cache

Jore

Hi everyone,

Just chasing up below, if anyone has any suggestions?

So to recap, the situation is, I have nginx running Wordpress with the Hypercache plugin but only the homepage is cached, other pages "miss" according to page headers.

Here is contents of the sites-enabled conf in question:


server {
        listen 80;
        listen 443 ssl http2;

        server_name NAMEOFSITECHANGED.COM;

        ssl_certificate /etc/nginx/ssl/NAMEOFSITECHANGED.COM.crt;
        ssl_certificate_key /etc/nginx/ssl/NAMEOFSITECHANGED.COM.key;
        keepalive_timeout 70;

        #enables all versions of TLS, but not SSLv2 or 3 which are crap and now deprecated.
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

        #disable weak ciphers
        ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
        ssl_prefer_server_ciphers on;


        root /var/www/NAMEOFSITECHANGED.COM;

        access_log /var/log/nginx/NAMEOFSITECHANGED.COM_access.log;
        error_log /var/log/nginx/NAMEOFSITECHANGED.COM_error.log;


        # don't cache anything using 'post' such as a form on subscribe page
         if ($request_method = POST) { set $skip_cache 1; }

        # don't cache URLs containing the following elements
        if ($request_uri ~* "/wp-admin/|wp-.*.php|index.php|preview=true") { set $skip_cache 1; }

        # don't use the cache for logged in users
        if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in|nCacheBypass") { set $skip_cache 1; }


        #main
        location / {

            index index.htm index.php;
            try_files $uri $uri/ /index.php?$args;
            error_page 404 = /404;

            #handle old permalink URLs and rewrite
            #rewrite ^/?video/(.*) /$1 permanent;
        }


        #pass the PHP scripts to FastCGI
        location ~ \.php$ {

            include snippets/fastcgi-php.conf;
            include fastcgi_params;
          
            fastcgi_pass unix:/run/php/php7.3-fpm.sock;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_cache_bypass $skip_cache;
            fastcgi_cache WORDPRESS;
            fastcgi_cache_valid  60m;

            error_page 404 = /404;
        }


        #no log on static files and expires header is set to maximum age
        location ~* ^.+\.(css|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|js|gif|png|ico)$ {
            access_log off;
            log_not_found off;
            expires max;
            add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
       }
}


And contents of /etc/nginx/nginx.conf:

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

events {
    worker_connections 8192;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

        #jore - extend times for SSL handshake etc to try keep server load low
        ssl_session_cache   shared:SSL:10m;
        ssl_session_timeout 10m;

    #jore - turn off server version and headers
    server_tokens off;

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

    client_max_body_size 128M;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

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


    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##
    # Comment out to set individual site log locations in their own conf

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

    #jore - change the format of nginx http logs a little to suit awstats
    log_format main     '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for"';


    ##
    # 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 text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    #jore - set up settings for memcached
        fastcgi_cache_path /var/www/memcached levels=1:2 keys_zone=WORDPRESS:100m inactive=1440m;
        fastcgi_cache_key "$scheme$request_method$host$request_uri"; 
        fastcgi_cache_use_stale error timeout invalid_header http_500;
        fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
        add_header X-Cached $upstream_cache_status;

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



/etc/nginx/conf.d is empty.

Any ideas as to what I've messed up?

Thanks!
Jore




On 25/5/20 5:07 am, Jore wrote:

Hi there,

Thanks for that.

Could you provide an example conf by any chance please, so I can get my head around that?

Thanks!
Jore


On 24/5/20 8:56 am, Alex Evonosky wrote:
Jore-

I applied the proxy_hide_header for no-cache headers to NGINX can process it and cache it.

On Sat, May 23, 2020 at 5:17 PM Jore <[hidden email]> wrote:

Hi Alex/all,

How did you fix?

I've got a very similar issue.

nginx running Wordpress with the Hypercache plugin but only the homepage is cached, other pages "miss" according to page headers.

Thanks,
Jore


On 24/5/20 7:04 am, Alex Evonosky wrote:
Disregard, found the issue.

thank you.

On Sat, May 23, 2020 at 4:18 PM Alex Evonosky <[hidden email]> wrote:
"Can you be more specific? Which "cache"? Browser cache? Nginx content
cache? try_files has nothing to do with caching..."


Nginx content cache


"Either way, you need to check your headers to ensure that they allow
caching for said pages. Also if any cookies are being sent then nginx
won't cache the page."


I looked at the headers using CURL..  

The issue seems this:


The request hits NGINX and the backend server(s) for Wordpress are cached just fine from just the FQDN --- example.com

however, if I try to go to say, example.com/?page_id=1234, the headers do not show NGINX anymore, as only the servers for Wordpress show up; Almost like a 
cache punch-hole.


===== proxy.conf ====

proxy_cache_path /tmp/cache keys_zone=my_cache:10m max_size=10m inactive=60m;

#proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header X-Cache-Status $upstream_cache_status;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;



==== nginx.conf ====

http {
        upstream example.com {
        least_conn;
        server 10.10.10.138:8999;
        server 10.10.10.84:8999;
        }

server {
listen 82;
location / {
try_files $uri $uri/ /$args /index.php?$args;
proxy_cache my_cache;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
proxy_cache_background_update on;
proxy_pass http://example.com;
proxy_cache_valid any 60m;
proxy_cache_methods GET HEAD POST;
proxy_http_version 1.1;
proxy_set_header Connection keep-alive;
proxy_ignore_headers Cache-Control Expires Set-Cookie;
      }
}

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

gzip on;
gzip_disable "msie6";

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

}





Thank you,
Alex




On Sat, May 23, 2020 at 8:43 AM J.R. <[hidden email]> wrote:
> And the main page caches OK, but any page the resides on the "?page_id" is
> not getting cached.  Is there more to the "try_files" that needs applied
> for caching of these permalinks?

Can you be more specific? Which "cache"? Browser cache? Nginx content
cache? try_files has nothing to do with caching...

Either way, you need to check your headers to ensure that they allow
caching for said pages. Also if any cookies are being sent then nginx
won't cache the page.
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Quick question on NGINX cache

Francis Daly
On Thu, May 28, 2020 at 01:20:04PM +1000, Jore wrote:

Hi there,

> Just chasing up below, if anyone has any suggestions?

What request do you make?
What response do you get?
What response do you want instead?

> So to recap, the situation is, I have nginx running Wordpress with the
> Hypercache plugin but only the homepage is cached, other pages "miss"
> according to page headers.

Can you show the request headers going from your browser to nginx?

It looks like you set $skip_cache if certain Cookie values are included
in the request. Or if the request includes "index.php".

If that does not show the problem -- can you show the response headers
coming from upstream to nginx? That might indicate if the pages are not
being cached by nginx.

Cheers,

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx