# Incoming X-Forwarded-For in conditional evaulation

**URL:** <https://www.ruby-forum.com/t/incoming-x-forwarded-for-in-conditional-evaulation/198159>\
**Category:** NGINX\
**Created:** [October 27, 2010, 12:40pm UTC](https://www.ruby-forum.com/t/incoming-x-forwarded-for-in-conditional-evaulation/198159 "2010-10-27T12:40:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkezSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Post date:** [October 27, 2010, 12:40pm UTC](https://www.ruby-forum.com/t/incoming-x-forwarded-for-in-conditional-evaulation/198159/1 "2010-10-27T12:40:06Z")

</div>

Hi.

I’ve set up nginx as a front-end for apache with mod\_rpaf.

## My config (parts that are meaningful for this thread) is:

http {  
proxy\_set\_header Host $host;  
proxy\_set\_header X-Forwarded-For $remote\_addr;

```
server {
    listen 80;
    server_name ~^www\.domain\.com$;
    location / {
        proxy_pass http://127.0.0.1:80;
    }
}

```

## }

This works fine. But now I need to bypass original incoming  
X-Forwarded-For without change if it equals to ‘1.2.3.4’ or ‘2.3.4.5’.

I’ve tried to filter like this:  
if ($http\_X-Forwarded-For = “1.2.3.4”) { proxy\_set\_header  
X-Forwarded-For “1.2.3.4”; }  
but that didn’t work. How do I evaluate incoming custom HTTP headers  
(those not having their own dedicated variables like $content\_length  
and others) in config file?

---

<div class="post-metadata">

**Author:** ![Andrey\_Semyonov](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9fc29f/32.png) [@Andrey\_Semyonov](https://www.ruby-forum.com/u/Andrey_Semyonov)\
**Post date:** [October 27, 2010, 1:49pm UTC](https://www.ruby-forum.com/t/incoming-x-forwarded-for-in-conditional-evaulation/198159/2 "2010-10-27T13:49:52Z")

</div>

On Wed, Oct 27, 2010 at 02:38:35PM +0400, Andrey Semyonov wrote:

Hi there,

> I’ve tried to filter like this:  
> if ($http\_X-Forwarded-For = “1.2.3.4”) { proxy\_set\_header  
> X-Forwarded-For “1.2.3.4”; }  
> but that didn’t work. How do I evaluate incoming custom HTTP headers  
> (those not having their own dedicated variables like $content\_length  
> and others) in config file?

Without having tested whether this if/set works here:

[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpRewriteModule#if) gives some examples like

if ($http\_user\_agent ~ MSIE) {

and

if ($http\_cookie ~\* “id=([^;] +)(?:;|$)” ) {

which suggest the pattern used; while

[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpCoreModule#Variables) says

“”"  
$http\_HEADER

The value of the HTTP header HEADER when converted to lowercase and  
with ‘dashes’ converted to ‘underscores’, e.g. $http\_user\_agent,  
$http\_referer…;  
“”"

All the best,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
