我想在VHOST文件中定义白名单IP(myIP1,myIP2),以便只允许特定的IP地址在apache 2.4中访问我的网站。我尝试了几种方法,但它的工作并不像我预期的那样。我尝试了什么:
1。第一个
<Directory "/var/www/html/website">
<RequireAny>
Require ip myIP1
Require ip myIP2
</RequireAny>
</Directory>
结果:我可以从任何地方访问该网站,而不仅仅是特定的IP
2。第二个
<Directory "/var/www/html/website">
Options All
AllowOverride All
Require all denied
Require ip myIP1
Require ip myIP2
</Directory>
结果:我可以从任何地方访问该网站,而不仅仅是特定的IP。
第3。第三个
<Directory "/var/www/html/website">
order deny,allow
deny from all
allow from myIP1
allow from myIP2
</Directory>
结果:即使是从myIP1或myIP2,我也无法从任何地方访问该网站。
这是我的.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]
有人可以告诉我我错了吗?并帮我纠正它。 感谢。
答案 0 :(得分:0)
这是使用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>