# Matching data within the host field of the header

**URL:** <https://www.ruby-forum.com/t/matching-data-within-the-host-field-of-the-header/166999>\
**Category:** NGINX\
**Created:** [May 1, 2009, 10:07pm UTC](https://www.ruby-forum.com/t/matching-data-within-the-host-field-of-the-header/166999 "2009-05-01T22:07:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Payam\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/59ef9b/32.png) [@Payam\_C](https://www.ruby-forum.com/u/Payam_C)\
**Post date:** [May 1, 2009, 10:07pm UTC](https://www.ruby-forum.com/t/matching-data-within-the-host-field-of-the-header/166999/1 "2009-05-01T22:07:39Z")

</div>

hey guys,

I cant seem to get this working… im trying to look at the host field  
within the header and match it against an ip, if it a hit, I want to  
redirect to 403  
Normally there should be a domain set as the host, not ip…

Thanks  
Payam

---

<div class="post-metadata">

**Author:** ![Payam\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/59ef9b/32.png) [@Payam\_C](https://www.ruby-forum.com/u/Payam_C)\
**Post date:** [May 2, 2009, 7:36am UTC](https://www.ruby-forum.com/t/matching-data-within-the-host-field-of-the-header/166999/2 "2009-05-02T07:36:59Z")

</div>

On Fri, May 01, 2009 at 12:55:15PM -0700, Payam C. wrote:

> I cant seem to get this working… im trying to look at the host field  
> within the header and match it against an ip, if it a hit, I want to  
> redirect to 403  
> Normally there should be a domain set as the host, not ip…

I do not understan the question, but probably you need something like  
this:

server {  
server\_name [www.domain.com](http://www.domain.com);  
…  
}

server {  
server\_name 192.168.1.1;  
return 403;  
}

---

<div class="post-metadata">

**Author:** ![Payam\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/59ef9b/32.png) [@Payam\_C](https://www.ruby-forum.com/u/Payam_C)\
**Post date:** [May 2, 2009, 8:08am UTC](https://www.ruby-forum.com/t/matching-data-within-the-host-field-of-the-header/166999/3 "2009-05-02T08:08:32Z")

</div>

2009/5/1 Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> server\_name [www.domain.com](http://www.domain.com);  
> Igor S.  
> [Igor Sysoev](http://sysoev.ru/en/)

Hi, this is what i was trying to do … i did not want to allow any  
site request where the $host = ip

```
    location / {

     proxy_intercept_errors on;
     proxy_cache one;
     proxy_cache_key x.x.x.x$request_uri;
     proxy_cache_valid 200 1h;
     proxy_cache_valid 404 5m;
     proxy_cache_use_stale error timeout invalid_header;

     if ($http_host ~* 'DOMAIN_HERE\.com') {
     proxy_pass http://LB_HTTP_x.x.x.x;
    break;
    }

    return 403;
    }

```

---

<div class="post-metadata">

**Author:** ![Payam\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/59ef9b/32.png) [@Payam\_C](https://www.ruby-forum.com/u/Payam_C)\
**Post date:** [May 2, 2009, 1:30pm UTC](https://www.ruby-forum.com/t/matching-data-within-the-host-field-of-the-header/166999/4 "2009-05-02T13:30:42Z")

</div>

On Fri, May 01, 2009 at 11:02:17PM -0700, Payam C. wrote:

> > ## server {
> 
> ```
> proxy_intercept_errors on;
> 
> return 403;
> }
> 
> ```

server {  
listen 80 default;  
server\_name \_;  
return 403;  
}

server {  
server\_name DOMAIN\_HERE.com;

```
 location / {

      proxy_intercept_errors on;
      proxy_cache one;
      proxy_cache_key x.x.x.x$request_uri;
      proxy_cache_valid 200 1h;
      proxy_cache_valid 404 5m;
      proxy_cache_use_stale error timeout invalid_header;

      proxy_pass http://LB_HTTP_x.x.x.x;
 }

```

}
