# Proxy only certain assets based on host header?

**URL:** <https://www.ruby-forum.com/t/proxy-only-certain-assets-based-on-host-header/245378>\
**Category:** NGINX\
**Created:** [May 24, 2013, 3:08am UTC](https://www.ruby-forum.com/t/proxy-only-certain-assets-based-on-host-header/245378 "2013-05-24T03:08:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [May 24, 2013, 3:08am UTC](https://www.ruby-forum.com/t/proxy-only-certain-assets-based-on-host-header/245378/1 "2013-05-24T03:08:07Z")

</div>

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](http://dnsname.com)) {  
location ~ ^/(stylesheets|images|javascripts|tools|flash|components)/  
{  
proxy\_pass [http://assethost](http://assethost)  
}  
}

Posted at Nginx Forum:

> **[proxy only certain assets based on host header?](https://forum.nginx.org/read.php?2,239494,239494#msg-239494)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![amagad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@amagad](https://www.ruby-forum.com/u/amagad)\
**Post date:** [May 24, 2013, 10:45am UTC](https://www.ruby-forum.com/t/proxy-only-certain-assets-based-on-host-header/245378/2 "2013-05-24T10:45:31Z")

</div>

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](http://assethost);  
}

----appa

---

<div class="post-metadata">

**Author:** ![amagad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a183cd/32.png) [@amagad](https://www.ruby-forum.com/u/amagad)\
**Post date:** [May 24, 2013, 3:08pm UTC](https://www.ruby-forum.com/t/proxy-only-certain-assets-based-on-host-header/245378/3 "2013-05-24T15:08:25Z")

</div>

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.

> **[nginx: donation](http://nginx.org/en/donation.html)**
