# Problem with "if" and "$remote\_addr"

**URL:** <https://www.ruby-forum.com/t/problem-with-if-and-remote-addr/224806>\
**Category:** NGINX\
**Created:** [November 27, 2012, 3:31am UTC](https://www.ruby-forum.com/t/problem-with-if-and-remote-addr/224806 "2012-11-27T03:31:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [November 27, 2012, 3:31am UTC](https://www.ruby-forum.com/t/problem-with-if-and-remote-addr/224806/1 "2012-11-27T03:31:37Z")

</div>

Hello,

I have strange problem. If i enter phpinfo file i get:  
\_SERVER[“REMOTE\_ADDR”] 80.239.242.1  
\_SERVER[“HTTP\_X\_FORWARDED\_FOR”] 79.173.35.1

So my IP is 80.239.242.1

I want to block access to location from other ips then ip in url. For  
example

location ~ ^/([0-9.]+)/(.\*?)$ {  
if ($remote\_addr != $1) {  
return 404;  
}  
}

But it doesn’t work correctly ☹

1.) I will see value of variable $remote\_addr, and it is correct result.  
The  
result is: 80.239.242.1  
location ~ ^/([0-9.]+)/(._?)$ {  
echo $remote\_addr;  
}  
2.) I will check that $remote\_addr is excaly parametr 1, and i get for  
the  
url “/80.239.242.1/1”  
location ~ ^/([0-9.]+)/(._?)$ {  
if ($remote\_addr != $1) {  
echo “$remote\_addr != $1”;  
}  
}

And the result is “79.173.35.1 != 80.239.242.1”

The question: Why variable $remote\_addr change value when i use “if”

Sorry for my english.

Thanks for reply  
Bart

Posted at Nginx Forum:

> **[Problem with "if" and "$remote\_addr"](https://forum.nginx.org/read.php?2,233248,233248#msg-233248)**
>
> Hello, I have strange problem. If i enter phpinfo file i get: \_SERVER\["REMOTE\_ADDR"\] 80.239.242.1 \_SERVER\["HTTP\_X\_FORWARDED\_FOR"\] 79.173.35.1 So my IP is 80.239.242.1 I want to block access to location from other ips then
