PLEASE remove these lines !!
if (req.url ~ "\.xml(\.gz)?$") {
return (pass);
}
Returning (pass) is a workaround but it's not how you want to use Varnish.
Varnish is here to cache pages and contents like sitemap_index.xml
You already implemented PURGE mechanism in VCL, so the simplest way to handle your sitemap_index.xml
issue is to PURGE it !
The basic principle is that sitemap_index.xml
need to be cached as long as no new post has been made. Then, every time a new post is created, you have to inform Varnish that sitemap_index.xml
is no longer valid by sending the HTTP request below (pasted from official documentation (1)) :
PURGE /sitemap_index.xml HTTP/1.0
Host: example.com
So, I guess you will have the choice by editing your module manually or by using the Varnish HTTP Purge / WordPress module (and probably hack it manually also) (2)