Forum: NGINX matching data within the host field of the header

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Payam C. (Guest)
on 2009-05-02 00:07
(Received via mailing list)
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
Igor S. (Guest)
on 2009-05-02 09:36
(Received via mailing list)
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;
    ...
}

server {
    server_name  192.168.1.1;
    return 403;
}
Payam C. (Guest)
on 2009-05-02 10:08
(Received via mailing list)
2009/5/1 Igor S. <removed_email_address@domain.invalid>:
>    server_name  www.domain.com;
> Igor S.
> 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;
        }
Igor S. (Guest)
on 2009-05-02 15:30
(Received via mailing list)
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;
     }
}
This topic is locked and can not be replied to.