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

Slashes gets added to cached file path #195

Closed lucasjahn closed 11 months ago

lucasjahn commented 11 months ago

Describe the bug I just wanted to debug the cache and found that it continous reports the following for basically all routes and adds more and more slashes to the file path which maybe resuls in not finding the file at all?.

I can still feel it is serving the cached version sometimes as the TTFB is under 60ms but not sure why it works?:

X-Rocket-Nginx-File:  /var/www/html/eisenhorn.com/eisenhorn_com/wp-content/cache/wp-rocket/eisenhorn.com//testimonials///index-https.html
X-Rocket-Nginx-Reason:  File not cached
X-Rocket-Nginx-Serving-Static: MISS

Versions What version of Nginx are you using ? nginx/1.18.0 (Ubuntu)

What version of Rocket-Nginx are you using ? Newset (pulled today, I think 3.1)

What version of WP Rocket are you using ? 3.14.2.1

Are you using Nginx as a reverse proxy (with Apache for instance) ? Serving directly with Nginx and php-fpm

To Reproduce Steps to reproduce the behaviour:

  1. Go to our Landing Page
  2. Check the Network Tab for the Response Headers (debug = true is set)

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

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

proxy_cache_path /var/run/nginx-cache/jscache levels=1:2 keys_zone=jscache:100m inactive=30d  use_temp_path=off max_size=100m;

server {
    server_name www.eisenhorn.com
                eisenhorn.at www.eisenhorn.at
                eisenhorn.be www.eisenhorn.be
                eisenhorn.ch www.eisenhorn.ch
                eisenhorn.cn www.eisenhorn.cn
                eisenhorn.cz www.eisenhorn.cz
                eisenhorn.de www.eisenhorn.de
                eisenhorn.dk www.eisenhorn.dk
                eisenhorn.eu www.eisenhorn.eu
                eisenhorn.fr www.eisenhorn.fr
                eisenhorn.ru www.eisenhorn.ru
                eisenhorn.se www.eisenhorn.se
                eisenhorn.tv www.eisenhorn.tv;
    return 301 $scheme://eisenhorn.com$request_uri;
}

server {
    server_name eisenhorn.com www.eisenhorn.com;
    root /var/www/html/eisenhorn.com/eisenhorn_com;
    index index.php index.html index.htm index.nginx-debian.html;

    listen 443 ssl http2; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/eisenhorn.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/eisenhorn.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    add_header Strict-Transport-Security "max-age=31536000" always; # managed by Certbot

    ssl_trusted_certificate /etc/letsencrypt/live/eisenhorn.com/chain.pem; # managed by Certbot
    ssl_stapling on; # managed by Certbot
    ssl_stapling_verify on; # managed by Certbot

    # Rocket-Nginx configuration
    include rocket-nginx/conf.d/default.conf;    

    resolver 9.9.9.9;
    set $plausible_script_url https://analytics.wortgewitzt.de/js/script.js;
    set $plausible_event_url https://analytics.wortgewitzt.de/api/event;

    rewrite ^/en/wp-login.php /wp-login.php break;

    location = /wp-content/themes/hub-child/src/js/script.js {
        proxy_pass $plausible_script_url;
        proxy_set_header Host analytics.wortgewitzt.de;
        proxy_ssl_name analytics.wortgewitzt.de;
        proxy_ssl_server_name on;
        proxy_ssl_session_reuse off;

        # Tiny, negligible performance improvement. Very optional.
        proxy_buffering on;

        # Cache the script for 6 hours, as long as plausible.io returns a valid response
        proxy_cache jscache;
        proxy_cache_valid 200 6h;
        proxy_cache_use_stale updating error timeout invalid_header http_500;

        # Optional. Adds a header to tell if you got a cache hit or miss
        add_header X-Cache $upstream_cache_status;
    }

    location = /wp-content/themes/hub-child/src/api/event {
        proxy_pass $plausible_event_url;
        proxy_set_header Host analytics.wortgewitzt.de;
        proxy_ssl_name analytics.wortgewitzt.de;
        proxy_ssl_server_name on;
        proxy_ssl_session_reuse off;
        proxy_buffering on;
        proxy_http_version 1.1;

        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host  $host;
    }

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    #location ~* wp-config.php {
    #    deny all;
    #}

    #location ~ /. {
    #    deny all;
    #    access_log off;
    #    log_not_found off;
    #}

    location ~* .(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
        expires max;
        log_not_found off;
        access_log off;
    }

}

server {
    if ($host = eisenhorn.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    server_name eisenhorn.com www.eisenhorn.com;
    root /var/www/html/eisenhorn.com/eisenhorn_com/maintenance;
    index index.php index.html index.htm index.nginx-debian.html;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

Expected behavior It should hit the static file without any additional slashes.

Additional context

maximejobin commented 11 months ago

The multiple slashes is totally normal and fine. That is a limitation of Nginx scripting.

I just visited the page you sent and here are the headers:

image

Everything is according to what it should do. Maybe you visited the page while the cached file did not exist.

I do not see any problem here so I will close the ticket as invalid. But if you feel like there is more to it, simply comment and reopen it.

lucasjahn commented 11 months ago

Absolutely working now. Strange, also tried out on different devices. All good, thanks though for looking into!