Nginx sitemap 404 not found [Bug Solved – Conflict With WP Cloudflare Cache]

#284105
  • Resolved mecra
    Rank Math free

    Hi everyone.
    First of all i found what the problem is and fixed it but i don’t know how this cause 404 not found problem. I will share this with you.

    I have a LEMP Debian Nginx server and wordpress site in it.

    I did not add this below code to my nginx i don’t use it, despite this sitemap works on my nginx without any problem.

    # START Nginx Rewrites for Rank Math Sitemaps
    rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;
    rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
    # END Nginx Rewrites for Rank Math Sitemaps

    But what is the problem?
    I use cloudflare and Wp cloudflare super cache.
    I activated browser cache from this plugin as well so plugin warned me to add this below block to my nginx.

    location ~* \.(xml|xsl)$ { add_header Cache-Control "no-cache, no-store, must-revalidate, max-age=0"; expires -1; }
    location /robots.txt { add_header Cache-Control "no-cache, no-store, must-revalidate, max-age=0"; expires -1; }
    location ~* \.(css|js|pdf)$ { add_header Cache-Control "public, must-revalidate, proxy-revalidate, immutable, max-age=2592000, stale-while-revalidate=86400, stale-if-error=604800"; expires 30d; }
    location ~* \.(jpg|jpeg|png|gif|ico|eot|swf|svg|webp|avif|ttf|otf|woff|woff2|ogg|mp4|mpeg|avi|mkv|webm|mp3)$ { add_header Cache-Control "public, must-revalidate, proxy-revalidate, immutable, max-age=31536000, stale-while-revalidate=86400, stale-if-error=604800"; expires 365d; }
    location /wp-cron.php { add_header Cache-Control "no-cache, no-store, must-revalidate, max-age=0"; expires -1; }
    location = /wp-content/wp-cloudflare-super-page-cache/wifisifrekirici.com/debug.log { access_log off; deny all; }

    Although if we don’t add this codes, wp cloudflare cache plugin doesn’t cache the sitemap and robots.txt. But this block has a line about xml/xsl and all block is actually for static pages.

    What is the conflict?

    At above code there is a line!
    location ~* \.(xml|xsl)$ { add_header Cache-Control "no-cache, no-store, must-revalidate, max-age=0"; expires -1; }

    If i add this line with above code block to nginx, sitemap gives 404 not found error when click sitemap url!
    If i remove this line from above block and add rest of codes sitemap works excellent without any error!

    I made some tests! I removed this line and checked the sitemap page from chome network editor.
    cloudfare bypassed the page without caching and there is a line!
    cache-control: no-cache, no-store, must-revalidate, max-age=0 Because without adding any code i told you Wp cloudflare super cache always doesn’t cache sitemap!

    I have 2 questions!

    1) But i dont’t know why my site gives 404 error on sitemap link when i add this line to nginx?
    location ~* \.(xml|xsl)$ { add_header Cache-Control "no-cache, no-store, must-revalidate, max-age=0"; expires -1; }

    2) How my sitemap works without adding below code, despite i have nginx server 🙂
    # START Nginx Rewrites for Rank Math Sitemaps
    rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;
    rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
    # END Nginx Rewrites for Rank Math Sitemaps

    Thanks very much.
    In this topic i shared the conflict between Wp cloudflare super cache and Rankmath on a nginx server!

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math today.

    1. We have not fully tested the code with the WP Cloudflare Super Cache functionality but if you tested that the sitemaps are not cached by that you can safely remove the rules used to bypass that from your installation.

    In fact, usually, Cloudflare doesn’t cache the sitemaps on any installation as is mentioned in our article here: https://rankmath.com/kb/exclude-sitemaps-from-caching/#cloudflare

    ​​​​​​2. This is only to be used if you are having trouble with the Rank Math sitemaps. We have plenty of users using Nginx that don’t add this code and the redirection rules work perfectly.

    Don’t hesitate to get in touch if you have any other questions.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 1 replies (of 1 total)

The ticket ‘Nginx sitemap 404 not found [Bug Solved – Conflict With WP Cloudflare Cache]’ is closed to new replies.