Help with setting proxy_header

Alexander Kolesen kolesen.a at gmail.com
Mon Mar 26 11:21:53 UTC 2012


> Hello!
> 
> I have a reverse proxy setup like this...
> 
> server {  
> ......
> ......
> 
>              if ($host = '23.71.33.142' ) { proxy_set_header Host
> www.domain.com; }
>                 location / { proxy_pass http://31.186.1.131:60/;  }
> 
> }
> 
> The problem is that i cannot have a proxy_set_header inside an IF like this.
> Basically what iam intending to do is.. If the remote client visits my server
> with the IP (23.71.33.142) as the header (by using http://23.71.33.142) I need
> to send hardcoded the header to the backend server si my backend server knows
> it should respond with the content of domain.com .  If they send any other
> header  then it needs to be past to the backend server to deal with intact (it
> can be domain.com / www.domain.com / sub.domain.com )
> 
> Thanks!
> 
> --Mike
> 

The more proper way is to use 'map' directive:

map $remote_addr $myhost {
    default $http_host;
    23.71.33.142 www.domain.com;
}

server {
...
    location / {
        proxy_set_header Host $myhost;
    }
...
}



More information about the nginx mailing list