You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Krzysztof Dajka <al...@gmail.com> on 2010/04/22 13:00:29 UTC

[users@httpd] Negation of Remote_Addr in SetEnvIf directive

Hi,

I have a bunch of apache servers which are load balanced. I have configured
them in such manner that each server adds header
X-Server-Name with proper hostname.

In my apache.conf I have:

PassEnv HOSTNAME
Header add X-Server-Name "%{HOSTNAME}e"

I have exported HOSTNAME before launching apache and everything works as it
should.
But I would like to configure apache to show hostname only for my inner
network 10.
So I added SetEnvIf:

PassEnv HOSTNAME
SetEnvIf Remote_Addr !^10\. HOSTNAME=foo.bar.com
Header add X-Server-Name "%{HOSTNAME}e"

but negation of network didn't work, I have also tried:
SetEnvIf Remote_Addr [^(10\.)] HOSTNAME=foo.bar.com

but it didn't worked either.
Has anyone used negation in SetEnvIf Remote_Addr ?

Documentation says:
Syntax:    SetEnvIf attribute regex [!]env-variable[=value]
[[!]env-variable[=value]] ...

so why any of those regex's doesn't work?

Thanks in advance

Re: [users@httpd] Negation of Remote_Addr in SetEnvIf directive

Posted by Krzysztof Dajka <al...@gmail.com>.
> Apache 2.0 and later uses PCRE, and neither of those expressions mean
> what you're describing.  SetEnvIf itself doesn't negate the result of
> the regex match with a flag.
>
> I don't fully understand your logic, but If you want your SetEnvIf to
> only take action when the remote address doesn't begin with "10.", try
> something like:
>
> ^((?!10\.).+)
>

Thanks a lot this regex works like a charm.

Re: [users@httpd] Negation of Remote_Addr in SetEnvIf directive

Posted by Eric Covener <co...@gmail.com>.
> SetEnvIf Remote_Addr !^10\. HOSTNAME=foo.bar.com
> Header add X-Server-Name "%{HOSTNAME}e"
> but negation of network didn't work, I have also tried:
> SetEnvIf Remote_Addr [^(10\.)] HOSTNAME=foo.bar.com
> but it didn't worked either.
> Has anyone used negation in SetEnvIf Remote_Addr ?
> Documentation says:
> Syntax:    SetEnvIf attribute regex [!]env-variable[=value]
> [[!]env-variable[=value]] ...
> so why any of those regex's doesn't work?

Apache 2.0 and later uses PCRE, and neither of those expressions mean
what you're describing.  SetEnvIf itself doesn't negate the result of
the regex match with a flag.

I don't fully understand your logic, but If you want your SetEnvIf to
only take action when the remote address doesn't begin with "10.", try
something like:

^((?!10\.).+)




-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org