Nginx location block for specific path and certain file types

nginx, reverse-proxy, wordpress

Solution

I had similar problem with my images. In my applications, images were being served from two different locations.

You can specify different sources based on url pattern. Your solution would then look something like this.

location ~* ^/blog/.+\.(xml)$ {
    root /some/path/;
    expires 90d;
}

location ~* \.(xml|js|jpg|png|css|html|otf|eot|svg|ttf)$ {
    root /some/other/path/;
    expires 30d;
    index index.html;
}

Problem

I am having trouble defining a location block for certain paths and file types. I am using wordpress and using a plugin which generates dynamic sitemaps..It redirects to path like sitemapindex.xml, which do not actually exist and nginx is trying to serve it statically. I need to be able to pass this to apache I need to send anything that is http://example.com/blog/*.xml to apache. This is what i am trying, which does not work.. so for instance: ``` http://example.com/blog/post.xml or http://example.com/blog/sitemapindex.xml ``` nginx config ``` server { location ~* ^/blog/*.xml$ { include /etc/nginx/proxy_params; proxy_pass http://127.0.0.1:8080; } } ``` what is the correct syntax Thanks

Original source