Proxy only certain assets based on host header?

We’re trying to proxy only certain assets like png|jpg|css only when the
host header is a certain DNS name. I tried to do this in the proxy.conf
file
using something the example below but it doesnt like the if statement.
Is
there a way to have nginx do what I am looking for?

if ($http_host = dnsname.com) {
location ~ ^/(stylesheets|images|javascripts|tools|flash|components)/
{
proxy_pass http://assethost
}
}

Posted at Nginx Forum:

location ~ ^/(?:stylesheets|images|javascripts|tools|flash|components)/
{
error_page 418 = @proxied_assets;

 if ($http_host = dnsname.com) {
     return 418;
 }

# add other directives here if need be...

}

location @proxied-assets {
proxy_pass http://assethost;
}

----appa

Hello!

On Thu, May 23, 2013 at 09:07:21PM -0400, amagad wrote:

}
Yes, sure. Use separate server{} block for a domain name you want
to be handled specially, e.g.:

 server {
     server_name foo.example.com;

     location / {
         # just serve anything as static
     }
 }

 server {
     server_name bar.example.com;

     location / {
         # server anything as static...
     }

     location /images/ {
         # ... but proxy images to a backend
         proxy_pass http://backend;
     }
 }


Maxim D.
http://nginx.org/en/donation.html