SatelliteWP / rocket-nginx

Rocket-Nginx is a Nginx configuration that makes WP-Rocket even faster by serving static pages directly without loading WordPress or PHP.
MIT License
579 stars 129 forks source link

Rocket Nginx changes Header on some sites #186

Closed furchtlos76 closed 1 year ago

furchtlos76 commented 1 year ago

Describe the bug

My Response Header shows

cache-control max-age=31536000 x-rocket-nginx-serving-static: HIT

Should it not show:

Cache-Control "no-cache, no-store, must-revalidate"

When the html file is cached and delivered by rocket nginx? So changes on the site result in always open the latest html version and not a cached version?

Versions What version of Nginx are you using ? 1.2.20 What version of Rocket-Nginx are you using ? latest 3.0 What version of WP Rocket are you using ? latest Are you using Nginx as a reverse proxy (with Apache for instance) ? yes

To Reproduce Steps to reproduce the behaviour:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Did you activate the debug in Rocket-Nginx ? Please do and include any headers.

Make sure you include ALL Nginx configuration files you are using. Remove any sensitive information before submitting.

Expected behavior A clear and concise description of what you expected to happen.

Additional context Add any other context about the problem here.

maximejobin commented 1 year ago

It's pretty hard to help you without seeing the configuration you are using and the website where it is used.

Please include:

Thank you

furchtlos76 commented 1 year ago

Thanks so much. I could get everything sorted now, just this last problem is there. As you wrote in another issue, you added

Add header to HTML cached files

location ~ /wp-content/cache/wp-rocket/.*html$ { add_header Cache-Control "no-cache, no-store, must-revalidate";

in your default configuration, so that users dont get old cached html files. Right? I have exactly that problem sometimes, that users say, they only see an old version of the website. So i checked headers for example on:

https://webbkoll.dataskydd.net/de/results?url=http%3A%2F%2Ftheaterverein-dogern.de

Those Header show:

cache-control max-age=31536000 x-rocket-nginx-serving-static: HIT

But, for my understanding of your code above it should be

Cache-Control no-cache, no-store, must-revalidate

Which would adress browser to NOT cache this html file! Or am i wrong?

your ini file (if modified) - nothing modified the generated configuration file - nothing modified your main configuration file for that site the website URL - for example www.theaterverein-dogern.de

maximejobin commented 1 year ago

The cache-control max-age does not come from Rocket-Nginx.

furchtlos76 commented 1 year ago

The cache-control max-age does not come from Rocket-Nginx.

ok i removed all other cache controll headers. inside nginx config. and server config. But still Cache Controll: no-cache, no-store, must-revalidate (that should come from Rocket Nginx) is not in the headers. Now the headers i get with https://webbkoll.dataskydd.net/ are:

content-encoding br content-type text/html date Fri, 14 Oct 2022 08:47:47 GMT etag W/"6348beb2-85aed" last-modified Fri, 14 Oct 2022 01:43:14 GMT referrer-policy strict-origin-when-cross-origin server nginx strict-transport-security max-age=15768000 vary Accept-Encoding x-content-type-options nosniff x-frame-options SAMEORIGIN x-rocket-nginx-serving-static HIT x-xss-protection 1, mode=block

In google chrome developer console:

date: Fri, 14 Oct 2022 08:47:21 GMT etag: "6348beb2-85aed" last-modified: Fri, 14 Oct 2022 01:43:14 GMT referrer-policy: strict-origin-when-cross-origin server: nginx strict-transport-security: max-age=15768000 x-content-type-options: nosniff x-frame-options: SAMEORIGIN x-rocket-nginx-serving-static: HIT x-xss-protection: 1, mode=block

there is no cache controll or expires anymore. Any idea why this could be? Should nnginx rocket not add that cache header all the time?

maximejobin commented 1 year ago

We are using the default stock configuration. Here are the headers:

image

If you are not getting that, it is because you set that value somewhere else in your configuration.

The default rocket-nginx.ini file specifies the header correctly:

; HTML Cache-Control
; Cache control header to use for html files
html_cache_control = "no-cache, no-store, must-revalidate"

See the reference: https://github.com/SatelliteWP/rocket-nginx/blob/master/rocket-nginx.ini.disabled#L24

Unfortunately, I cannot help more than that.

furchtlos76 commented 1 year ago

We are using the default stock configuration. Here are the headers:

image

If you are not getting that, it is because you set that value somewhere else in your configuration.

The default rocket-nginx.ini file specifies the header correctly:

; HTML Cache-Control
; Cache control header to use for html files
html_cache_control = "no-cache, no-store, must-revalidate"

See the reference: https://github.com/SatelliteWP/rocket-nginx/blob/master/rocket-nginx.ini.disabled#L24

Unfortunately, I cannot help more than that.

thanks, will take a look where those headers are maybe double, so they get lost.

furchtlos76 commented 1 year ago

I found the sollution, for anyone else having the same problem on plesk: https://talk.plesk.com/threads/nginx-browser-caching-for-static-resources.334497/#post-790630 - you have to remove html/htm from "serve static files with nginx..." box. Then it will proceed to the directives in vhost_nginx.conf or rocket-nginx and add the extra headers.