比方,一个站点有一个平安地区,如http://example.com/admin/“,我们只要受权用户或IP才接见/admin/部份。
1、在特定URL上设置基于IP的限定
起首编辑apache配置文件,并在virtualhost中增加以下条目。这将仅许可/admin URL接见192.168.10.11和123.45.67.89 IP。
<Location /admin> Order deny,allow Deny from all Allow from 192.168.10.11 Allow from 123.45.67.89 </Location>
保留Apache配置文件并运用以下敕令之一重新启动Apache效劳。
# service httpd restart # For RHEL based systems $ sudo service apache2 restart # For Debian based systems
我们尝试从恣意其他IP接见你的站点。同时还要在配置文件中搜检给定的ip。。
2、在特定URL上设置用户身份验证
编辑apache配置文件,并在网站virtualhost部份增加以下内容。
<Location /admin> AuthUserFile /var/www/htpasswd/.htpasswd AuthName "Password Protected Area" AuthType Basic Require valid-user </Location>
如今运用下面的敕令建立新的htpasswd文件并增加一个新用户。
# htpasswd -cm /var/www/htpasswd/.htpasswd myuser New password: Re-type new password: Adding password for user myuser
重新启动Apache并接见你的网站URL,它将提醒登录的细致信息。
# service httpd restart # For RHEL based systems $ sudo service apache2 restart # For Debian based systems
本篇文章到这里就已悉数完毕了,更多其他精彩内容人人能够关注ki4网的PHP视频教程栏目!
以上就是怎样庇护Apache中的特定URL的细致内容,更多请关注ki4网别的相干文章!