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
On Sat, Mar 24, 2012 at 12:40:06AM +0000, Micheal W. wrote:
Hi there,
if ($host = '23.71.33.142' ) { proxy_set_header Host
www.domain.com; }
location / { proxy_pass http://31.186.1.131:60/; }
You want to have
proxy_set_header Host $host;
unless $host is this IP address, in which case you want a different
value?
set $myhost $host;
if ($host = ‘23.71.33.142’) { set $myhost www.domain.com; }
proxy_set_header Host $myhost;
where the first two are at server{} level, and the last is at server{}
or location{} level.
Using the “map” directive is another way of setting your $myhost
variable.
f
Francis D. [email protected]
location / { proxy_pass http://31.186.1.131:60/; }
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;
}
…
}