How do I set IP access / password restrictions in Apache?

I'd like to restrict access to my Rails app (running on Apache/Passenger) to just two IPs, but if the visitor doesn't fall into those two IPs, I would like for him/her to be prompted to enter a password that would allow any user with the proper credentials to access the site from anywhere.

I am new to configuring Apache and would appreciate any hints. Thanks!

Answers


You can do this with .htaccess files, something like:

AuthName "Lee's Secret Area"
AuthType Basic 
<Limit GET POST>
order deny,allow
deny from all
allow from 199.166.210.
allow from .golden.net
allow from proxy.aol.com
allow from fish.wiretap.net
</Limit>

for instance


Need Your Help

Nunit async test exception assertion

c# nunit async-await

I have a controller UserController with this action

How to report progress of a JavaScript function?

javascript progress repaint

I have a JavaScript function which is quite long and performs a number of tasks, I would like to report progress to the user by updating the contents of a SPAN element with a message as I go. I tr...