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

MISS if use HTTP3.0 #217

Closed PauloOF closed 3 months ago

PauloOF commented 3 months ago

Hi Maxime,

Do you know why I'm getting "x-rocket-nginx-serving-static: MISS" if use HTTP3.0 protocol? See bellow headers thawe have got with curl.

HTTP/3 200 server: nginx date: Fri, 14 Jun 2024 18:06:17 GMT content-type: text/html; charset=UTF-8 vary: accept-encoding last-modified: Fri, 14 Jun 2024 18:00:02 GMT alt-svc: h3=":443"; ma=86400 strict-transport-security: max-age=15768000; includeSubDomains x-rocket-nginx-serving-static: MISS x-content-type-options: nosniff x-frame-options: sameorigin

HTTP/2 200 server: nginx date: Fri, 14 Jun 2024 18:09:33 GMT content-type: text/html content-length: 341885 last-modified: Fri, 14 Jun 2024 18:00:02 GMT vary: Accept-Encoding etag: "666c8522-5377d" alt-svc: h3=":443"; ma=86400 vary: Accept-Encoding, Cookie cache-control: public, max-age=600 x-content-type-options: nosniff x-frame-options: sameorigin strict-transport-security: max-age=31536000 x-rocket-nginx-serving-static: HIT accept-ranges: bytes

maximejobin commented 3 months ago

Please activate the debug and post the headers you see. This will help me help you!

PauloOF commented 3 months ago

Headers with set $rocket_debug 1;

Curl With HTTP3:

HTTP/3 200 server: nginx date: Mon, 17 Jun 2024 16:20:17 GMT content-type: text/html; charset=UTF-8 vary: accept-encoding last-modified: Mon, 17 Jun 2024 16:00:02 GMT alt-svc: h3=":443"; ma=86400 strict-transport-security: max-age=15768000; includeSubDomains x-rocket-nginx-serving-static: MISS x-rocket-nginx-reason: File not cached x-rocket-nginx-file: /var/www/vhosts/domain.com/httpdocs/wp-content/cache/wp-rocket/////index-https.html x-content-type-options: nosniff x-frame-options: sameorigin

Curl with http2 HTTP/2 200 server: nginx date: Mon, 17 Jun 2024 16:22:08 GMT content-type: text/html content-length: 339684 last-modified: Mon, 17 Jun 2024 16:00:02 GMT vary: Accept-Encoding etag: "66705d82-52ee4" alt-svc: h3=":443";ma=86400,h3-29=":443";ma=86400,h3-27=":443";ma=86400 vary: Accept-Encoding, Cookie cache-control: public, max-age=600 x-content-type-options: nosniff x-frame-options: sameorigin strict-transport-security: max-age=31536000 x-rocket-nginx-serving-static: HIT x-rocket-nginx-reason: /wp-content/cache/wp-rocket/domain.com////index-https.html x-rocket-nginx-file: /var/www/vhosts/domain.com/httpdocs/wp-content/cache/wp-rocket/domain.com////index-https.html accept-ranges: bytes

PauloOF commented 3 months ago

Hi Maxime,

We have made a few tests and the at the fastcgi.conf we have added the line

fastcgi_param HTTP_HOST $host;

With http3 active this line its required, to avoide redirect error in all pages. Not sure if this is related with the issue.

I suspect the error its related with the $http_host variable at the default.com rocket-nginx. For testing purposes we have replaced the variable $http_host in all existing lines by domain.com. With this replacement the system started to work again, showing "HIT" in all pages.

Please let me know any comment you may have, since this replacement seems not to be the best and final solution.

maximejobin commented 3 months ago

It seems like there was a missing variable in your Nginx/Fast CGI configuration.

Instead of replacing $http_host manually, you should edit your Fast CGI param to bind the host to the variable. That way, the script will work properly.

By not doing this, you surely WILL have issues with other scripts (WordPress itself, plugins, etc.) at some point.

I will close the issue as this is related to your Nginx & Fast CGI configuration. If you find the solution, it would be nice if you comment below with your findings!

I wish you the best!

PauloOF commented 3 months ago

Thanks!

I'm using fastcgi_param HTTP_HOST $host; at fastcgi.conf and seems its necessary to replace all usages of [$http_host] with [$host] in nginx config files.

After a full server check, I have confirmed that only rocket-nginx uses [$http_host] instead of $host.

I think that this its the solution to make compatibility of the h3 protocol.

maximejobin commented 3 months ago

That is weird as we did not invent that variable!

If it's working for HTTP2, clearly your HTTP2 is configured to use it. You might want to check.

PauloOF commented 3 months ago

No doubt about HTTP2. It seems there is a diferent aproach on HTTP3 protocol, since its based on UDP. Anyway its quite new, and still may change.

Thanks for your help.