• Resolved realmoag

    (@realmoag)


    Hello,
    I am trying to use the plugin but I am getting this error knowing that I am using Nginx.
    Here is my nginx config:

    # Upstream to abstract backend connection(s) for php
    
    upstream php {
    
            server unix:/run/php/php8.1-fpm.sock;
    
            server 127.0.0.1:9000;
    
    }
    
    add_header X-Cache $upstream_cache_status;
    
    server {
    
    # BEGIN Converter for Media
    
    set $ext_avif ".avif";
    
    if ($http_accept !~* "image/avif") {
    
        set $ext_avif "";
    
    }
    
    set $ext_webp ".webp";
    
    if ($http_accept !~* "image/webp") {
    
        set $ext_webp "";
    
    }
    
    location ~ /wp-content/(?<path>.+)\.(?<ext>jpe?g|png|gif|webp)$ {
    
        add_header Vary Accept;
    
        expires 365d;
    
        try_files
    
            /wp-content/uploads-webpc/$path.$ext$ext_avif
    
            /wp-content/uploads-webpc/$path.$ext$ext_webp
    
            $uri =404;
    
    }
    
    # END Converter for Media
    
            ## Your website name goes here.
    
            server_name sirodex.com;
    
            ## Your only path reference.
    
            root /srv/www/sirodex.com;
    
            ## This should be in your http block and if it is, it's not needed here.
    
            index index.php;
    
            location = /favicon.ico {
    
                    log_not_found off;
    
                    access_log off;
    
            }
    
            location = /robots.txt {
    
                    allow all;
    
                    log_not_found off;
    
                    access_log off;
    
            }
    
            location / {
    
                    # This is cool because no php is touched for static content.
    
                    # include the "?$args" part so non-default permalinks doesn't break when using query string
    
                    try_files $uri $uri/ /index.php?$args;
    
            }
    
    set $skip_cache 0;
    
    # POST requests and urls with a query string should always go to PHP
    
    if ($request_method = POST) {
    
        set $skip_cache 1;
    
    }
    
    if ($query_string != "") {
    
        set $skip_cache 1;
    
    }
    
    # Don't cache uris containing the following segments
    
    if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|^/feed/*|/tag/.*/feed/*|index.php|/.*sitemap.*\.(xml|xsl)") {
    
        set $skip_cache 1;
    
    }
    
    #Skip cache on WooCommerce pages
    
    if ($request_uri ~* "/store.*|/cart.*|/my-account.*|/checkout.*|/addons.*") {
    
             set $skip_cache 1;
    
    }
    
    #Skip cache when WooCommerce cart is not empty
    
    #if ( $cookie_woocommerce_items_in_cart != "0" ) {
    
    #    set $skip_cache 1;
    
    #}
    
    #Skip cache for WooCommerce query string
    
    # if ( $arg_add-to-cart != "" ) {
    
    #      set $skip_cache 1;
    
    # }
    
    # Don't use the cache for logged in users or recent commenters
    
    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
    
        set $skip_cache 1;
    
    }
    
            location ~ \.php$ {
    
                    #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    
                    include fastcgi_params;
    
                    fastcgi_intercept_errors on;
    
                    fastcgi_pass php;
    
                    #The following parameter can be also included in fastcgi_params file
    
                    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    
                    fastcgi_cache MYAPP;
    
                    fastcgi_cache_valid 200 60m;
    
                    fastcgi_cache_bypass $skip_cache;
    
                    fastcgi_no_cache $skip_cache;
    
            }
    
            location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    
                    expires max;
    
                    log_not_found off;
    
            }
    
    #add_header X-CacheEND $upstream_cache_status;
    
    }
    
    fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=MYAPP:100m inactive=60m;
    
    fastcgi_cache_key "$scheme$request_method$host$request_uri";

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hi @realmoag,

    Thank you for your message.

    You’re using Cloudflare, right? Have you entered data for Cloudflare in the plugin settings, in the CDN Settings section?

    Best,
    Mateusz

    Thread Starter realmoag

    (@realmoag)

    Hello,

    Thank you for your reply.

    Yes I am using Cloudflare.

    I can’t seem to find the section that you have mentioned, can you please elaborate and explain more?

    Thanks in advance

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @realmoag There are four tabs in the plugin settings panel. These tabs appear at the top of the plugin settings page: General Settings, Advanced Settings, CDN Settings, and Help Center.

    Thread Starter realmoag

    (@realmoag)

    Sorry for the confusion, I had an older version of the plugin and I have updated it and entered the global Cloudflare API key and the zone id and I am still getting this error.

    Please, contact your hosting’s technical support or CDN’s support and send them the following message:I have a problem with the cache for HTTP requests on my website – https://sirodex.com. This prevents JPEG or PNG files from being dynamically redirected to WebP or AVIF, depending on whether the browser supports the format. Here are potential sources of this issue:
    – the server or CDN server does not support the “Vary: Accept” HTTP header or handles it incorrectly (the cache for redirects should be based not only on the URL to the file, but also on the value of the Accept header sent by the browser)
    – the server or CDN server does not support the “Cache-Control: private” HTTP header or handles it incorrectly (this header should be able to disable caching for static files on the CDN server or proxy server)
    – the website is running on the Nginx server without support for .htaccess files and not all the steps described in the plugin FAQ (in the question: Configuration for Nginx) have been followed correctly

    Thread Starter realmoag

    (@realmoag)

    I have just bought a Cloudflare pro plan which If I am not mistaken allows me to use vary: accept header but still I couldn’t figure out how to fix the issue.

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @realmoag Then the error is related to your Nginx configuration. It’s probably related to this bit of configuration:

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    
            expires max;
    
            log_not_found off;
    
    }

    Please read question “Configuration for Nginx” in the plugin FAQ carefully. Pay special attention to step 4.

    Thread Starter realmoag

    (@realmoag)

    I did update the configuration before I have posted this and removed png,jpg,jpeg from the config but unfortunately its still giving the same error.
    I suspect its Cloudflare issue because when I am using development mode in Cloudflare the error goes away but I want to know how to fix the settings for cloudflare.

    here is the nginx config:

    # Upstream to abstract backend connection(s) for php
    
    upstream php {
    
            server unix:/run/php/php8.1-fpm.sock;
    
            server 127.0.0.1:9000;
    
    }
    
    add_header X-Cache $upstream_cache_status;
    
    server {
    
    # BEGIN Converter for Media
    
    set $ext_avif ".avif";
    
    if ($http_accept !~* "image/avif") {
    
        set $ext_avif "";
    
    }
    
    set $ext_webp ".webp";
    
    if ($http_accept !~* "image/webp") {
    
        set $ext_webp "";
    
    }
    
    location ~ /wp-content/(?<path>.+)\.(?<ext>jpe?g|png|gif|webp)$ {
    
        add_header Vary Accept;
    
        expires 365d;
    
        try_files
    
            /wp-content/uploads-webpc/$path.$ext$ext_avif
    
            /wp-content/uploads-webpc/$path.$ext$ext_webp
    
            $uri =404;
    
    }
    
    # END Converter for Media
    
            ## Your website name goes here.
    
            server_name sirodex.com;
    
            ## Your only path reference.
    
            root /srv/www/sirodex.com;
    
            ## This should be in your http block and if it is, it's not needed here.
    
            index index.php;
    
            location = /favicon.ico {
    
                    log_not_found off;
    
                    access_log off;
    
            }
    
            location = /robots.txt {
    
                    allow all;
    
                    log_not_found off;
    
                    access_log off;
    
            }
    
            location / {
    
                    # This is cool because no php is touched for static content.
    
                    # include the "?$args" part so non-default permalinks doesn't break when using query string
    
                    try_files $uri $uri/ /index.php?$args;
    
            }
    
    set $skip_cache 0;
    
    # POST requests and urls with a query string should always go to PHP
    
    if ($request_method = POST) {
    
        set $skip_cache 1;
    
    }
    
    if ($query_string != "") {
    
        set $skip_cache 1;
    
    }
    
    # Don't cache uris containing the following segments
    
    if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|^/feed/*|/tag/.*/feed/*|index.php|/.*sitemap.*\.(xml|xsl)") {
    
        set $skip_cache 1;
    
    }
    
    #Skip cache on WooCommerce pages
    
    if ($request_uri ~* "/store.*|/cart.*|/my-account.*|/checkout.*|/addons.*") {
    
             set $skip_cache 1;
    
    }
    
    #Skip cache when WooCommerce cart is not empty
    
    #if ( $cookie_woocommerce_items_in_cart != "0" ) {
    
    #    set $skip_cache 1;
    
    #}
    
    #Skip cache for WooCommerce query string
    
    # if ( $arg_add-to-cart != "" ) {
    
    #      set $skip_cache 1;
    
    # }
    
    # Don't use the cache for logged in users or recent commenters
    
    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
    
        set $skip_cache 1;
    
    }
    
            location ~ \.php$ {
    
                    #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    
                    include fastcgi_params;
    
                    fastcgi_intercept_errors on;
    
                    fastcgi_pass php;
    
                    #The following parameter can be also included in fastcgi_params file
    
                    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    
                    fastcgi_cache MYAPP;
    
                    fastcgi_cache_valid 200 60m;
    
                    fastcgi_cache_bypass $skip_cache;
    
                    fastcgi_no_cache $skip_cache;
    
            }
    
            location ~* \.(js|css|ico)$ {
    
                    expires max;
    
                    log_not_found off;
    
            }
    
    #add_header X-CacheEND $upstream_cache_status;
    
    }
    
    fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=MYAPP:100m inactive=60m;
    
    fastcgi_cache_key "$scheme$request_method$host$request_uri";
    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @realmoag Do you have any rules in the Page Rules section of your Cloudflare configuration?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Error codes: rewrites_cached – nginx’ is closed to new replies.