7

With the following snippet, everyone can access both /foo and /bar

ProxyPass /foo http://example.com/foo
ProxyPassReverse /foo http://example.com/foo 
ProxyPass /bar http://example.com/bar
ProxyPassReverse /bar http://example.com/bar

But what if I want /foo to be accessible for everyone, and /bar only for requests coming from a specific IP, is this possible?

mobmad
  • 183
  • 1
  • 1
  • 6

3 Answers3

5

The answer should be as follows. I have included an IP and a subnet in one rule, for those who need to allow a whole subnet rather than a set of single IPs.

<Location /foo>
    Deny from all                       // **This rule is the most IMPORTANT**    
    Allow from 192.168.1.2 10.100       // The second value implies 10.100.0.0/16 subnet
    ProxyPass http://example.com/foo
    ProxyPassReverse http://example.com/foo
</Location>
Rumesh Bandara
  • 160
  • 1
  • 9
4
<Location /bar>
    Allow from 1.2.3.4 2.3.4.5 ...
    ProxyPass http://example.com/bar
    ProxyPassReverse http://example.com/bar
</Location>

Note the first argument to ProxyPass and ProxyPassReverse is implied here to be the target of the location block.

Kenster
  • 2,152
  • 16
  • 16
3

I think you can use a SetEnvIf directive checking the Remote Address (Remote_Addr).

With one IP:

SetEnvIf Remote_Addr "123.123.123.123" TRUST=yes

Checking multiple IPs with regular expression

SetEnvIf Remote_Addr "123\.123\.123\.123|134\.134\.(134\.(134|134)|134\.134)" TRUST=yes

I'm not sure you can do directly this:

ProxyPass /foo http://example.com/foo env=TRUST

But probably you can work with Rewrite Rules and obtain the same result...

For example you can rewrite to a particular page all the IP that are not trusted (env=!TRUST)

Hope it helps.

Halfgaar
  • 8,084
  • 6
  • 45
  • 86
tmow
  • 1,227
  • 9
  • 20
  • Passing env=TRUST gives a syntax error, but your second suggestion put me in the right direction. Adding a rewriterule BEFORE any proxy definitions in httpd.conf worked. See detailed instructions on this site: http://www.the-art-of-web.com/system/rewrite/#section_1 – mobmad Feb 15 '10 at 12:49