Reputation: 920
I'd like to define whitelist IPs (myIP1, myIP2) in VHOST file to allow only particular IP Addresses access my website in apache 2.4. I've tried with several ways but it's work is not as my expected. What I've tried:
1. The First
<Directory "/var/www/html/website">
<RequireAny>
Require ip myIP1
Require ip myIP2
</RequireAny>
</Directory>
Result: I can access the site from everywhere not only particular IPs
2. The Second
<Directory "/var/www/html/website">
Options All
AllowOverride All
Require all denied
Require ip myIP1
Require ip myIP2
</Directory>
Result: I can access the site from everywhere not only particular IPs.
3. The Third
<Directory "/var/www/html/website">
order deny,allow
deny from all
allow from myIP1
allow from myIP2
</Directory>
Result: I cannot access the site from everywhere even from myIP1 or myIP2.
This is my .htacess
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
Could someone can tell me what I'm wrong? And help me correct it. Thanks.
Upvotes: 1
Views: 2351
Reputation: 596
This is how to do it with Apache 2.4
<Directory "/var/YourSite/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride None
Require ip xx.xx.xx.xx
Require ip xx.xx.xx.xx
</Directory>
<Directory "/var/YourSite/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
Upvotes: 1