Rootop 服务器运维与web架构

apache 限制目录访问

| 暂无评论

比如说登陆nagios或者是其它监控软件等,都会提示输入用户名密码,才能登陆,其实就是在apache中限制目录访问权限。
通过用户名和密码的方式进行验证。

比如我这里将/var/www/html/a目录进行限制:
1、修改httpd.conf配置文件,添加:

<Directory “/var/www/html/a”>
AllowOverride AuthConfig
</Directory>

2、创建密码文件,添加用户venus:

[root@centos-6.5-x64 ~]#htpasswd -c /var/www/html/a/.htpasswd venus
New password:
Re-type new password:
Adding password for user venus

-c 代表创建,没有.htpasswd文件时才需要-c参数,-D 删除,可以man一下htpasswd

3、创建.htaccess文件

[root@centos-6.5-x64 ~]#cat /var/www/html/a/.htaccess

AuthName “please input your username ang password!”
AuthType Basic
AuthUserFile /var/www/html/a/.htpasswd
Require valid-user

AuthName 提示信息
AuthType 目前只实现了Basic和Digest(不常用)
这两个模块通常至少需要和一个认证支持模块(如mod_authn_file)和一个授权支持模块(如mod_authz_user)一起使用。
AuthUserFile 认证文件路径
Require 所有有效用户

重启apache测试。
访问http://192.168.1.102/a 弹出输入用户名密码即可。

附:

通过ip限制访问:https://www.rootop.org/pages/963.html

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/2204.html

作者:Venus

服务器运维与性能优化

发表回复