Jore
May 27, 2020 11:22PM
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 <community@thoughtmaybe.com
>> <mailto:community@thoughtmaybe.com>> 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
>>> <alex.evonosky@gmail.com <mailto:alex.evonosky@gmail.com>> 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 http://example.com
>>>
>>> however, if I try to go to say, example.com/?page_id=1234
>>> http://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 http://example.com {
>>>         least_conn;
>>>         server 10.10.10.138:8999 http://10.10.10.138:8999;
>>>         server 10.10.10.84:8999 http://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. <themadbeaker@gmail.com
>>> <mailto:themadbeaker@gmail.com>> 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
>>> nginx@nginx.org <mailto:nginx@nginx.org>
>>> http://mailman.nginx.org/mailman/listinfo/nginx
>>>
>>>
>>> _______________________________________________
>>> nginx mailing list
>>> nginx@nginx.org <mailto:nginx@nginx.org>
>>> http://mailman.nginx.org/mailman/listinfo/nginx
>> _______________________________________________
>> nginx mailing list
>> nginx@nginx.org <mailto:nginx@nginx.org>
>> http://mailman.nginx.org/mailman/listinfo/nginx
>>
>>
>> _______________________________________________
>> nginx mailing list
>> nginx@nginx.org
>> http://mailman.nginx.org/mailman/listinfo/nginx
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Quick question on NGINX cache

Alex Evonosky May 22, 2020 09:32PM

Re: Quick question on NGINX cache

J.R. May 23, 2020 08:44AM

Re: Quick question on NGINX cache

Alex Evonosky May 23, 2020 04:20PM

Re: Quick question on NGINX cache

Alex Evonosky May 23, 2020 05:06PM

Re: Quick question on NGINX cache

Jore May 23, 2020 05:18PM

Re: Quick question on NGINX cache

Alex Evonosky May 23, 2020 06:58PM

Re: Quick question on NGINX cache

Jore May 24, 2020 03:08PM

Re: Quick question on NGINX cache

Jore May 27, 2020 11:22PM

Re: Quick question on NGINX cache

Francis Daly May 28, 2020 08:28AM

RE: Re: Quick question on NGINX cache

Anonymous User May 23, 2020 05:26PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 237
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready