logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Conditional reverse proxy, based on IP whitelist
Author
kosie99



Joined: 23 Sep 2019
Posts: 1
Location: Swords

PostPosted: Mon 23 Sep '19 15:18    Post subject: Conditional reverse proxy, based on IP whitelist Reply with quote

I would like to achieve this with Apache:

If a client with an IP defined in whitelist.txt tries to access http://site1.com, I want to reverse proxy that to http://site2.com.

If the client IP is not in that list, I just want normal flow to occur and the index.html in htdocs to be served.

I was thinking of doing something along these lines, but I am not sure if that makes sense:

Code:

    RewriteMap iplist "txt:/usr/local/apache2/conf/wl.txt"
    RewriteCond "${iplist:%REMOTE_ADDR}" [ I AM NOT SURE ON THE SYNTAX HERE ]
    RewriteRule "^/(.*)" "http://site2.com/$1" [P]
    ProxyPassReverse / http://site2.com/


If the above, or a version of it works, will the normal index.html be served if an IP is not in the list? Is there a better way to achieve this?

Thanks!
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Tue 24 Sep '19 11:11    Post subject: Reply with quote

I think it works, it is like the black list example from https://httpd.apache.org/docs/trunk/rewrite/access.html#host-deny

Wouldn't is be easier just to deny the access for all others?
Back to top


Reply to topic   Topic: Conditional reverse proxy, based on IP whitelist View previous topic :: View next topic
Post new topic   Forum Index -> Apache