Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm using Apache Reverse Proxy, following is some of Apache Virtual Host configuration

ProxyRequests Off
<Proxy *>
        AddDefaultCharset off
        Order deny,allow
        Allow from all
</Proxy>
ProxyVia On
ProxyRequests Off
ProxyPreserveHost On
proxyPass /        ajp://127.0.0.1:8009/

Now I want to restrict request url like http://mysite.com/admin/tools in such a way that it should allow to access from particular IP address only. How can I achieve this ?

EDIT:

As of above requirement this answer is working fine, Suppose I want allow to access admin URL from one or two IP's and rest IP's I want to redirect to index page instead of showing forbidden error,how can I get this ?

share|improve this question

3 Answers 3

What version of apache are you using? One way to restrict access to resources based on the URL is to use

For example:

<Location /admin/tools>
  Order Deny,Allow
  Deny from all
  Allow from 192.168.1.34
</Location>
share|improve this answer
    
I'm using Apache2.2 on Ubuntu, I'll try how you have suggested,Thanks Krist –  Mahesh.D Apr 3 '13 at 10:06

As of above requirement this answer is working fine, Suppose I want allow to access admin URL from one or two IP's and rest IP's I want to redirect to index page instead of showing forbidden error,how can I get this ?

To expand @krist-van-besien answer, you can do that with the help of ErrorDocument for 403 Forbidden like this:

<Location /admin/tools>
  Order Deny,Allow
  Deny from all
  Allow from 192.168.1.34
  ErrorDocument 403 /index.php
</Location>

Please note, that the user should have permissions to view the page you're redirecting him to. For more info you can check this question: Allowing blocked IP to view 403 ErrorDocument

share|improve this answer

To expand on this scenario to apply to a RESTful web service endpoint vs calling the endpoint from a web page.

Is there a way to proxy requests from a local server's web page and forward them to the web service address along with allowing local internal network requests (developers) access to the web service endpoint, yet still restrict direct external WS endpoint requests?

For example, if the web service is running on Tomcat (port 8080) and we are using mod_proxy to redirect the apache requests from the web page on port 80 -> tomcat:8080/webservice in our web page service calls.

        <Location /admin/tools>
            Order Deny,Allow
            Deny from all
            Allow from localhost
            Allow from 127.0.0.1
            Allow from *local.domain.com
        </Location>
        ProxyPass /admin/tools http://localhost:8080/admin/tools
        ProxyPassReverse /admin/tools http://localhost:8080/admin/tools

When I try this, it locks the entire WS endpoint access including the web page request going the the proxy pass endpoint.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.