|
1。首先要有apache 的认证模块,默认都会安装。
2. 编辑httpd.conf文件 ,修改工作目录下的配置,将AllowOverride 更改为AuthConfig
<Directory /data/mrtgwww/>Options Indexes FollowSymLinksAllowOverride AuthConfigOrder allow,denyAllow from all</Directory>
3.用htpasswd创建一个密码文件,比如文件名叫 my.pass
创建
htpasswd -c -b my.pass myusername mypassword
添加用户
htpasswd -b my.pass newusername newpassword
4.将my.pass移动到一个非发布路径下之外的任何目录中,比如 /home/下
5. 在工作目录创建.htaccess 文件,文件内容为
AuthName "My Authorization Directory" # 显示名称AuthType Basic # 认证类型AuthUserFile /home/my.pass #认证文件位置Require valid-user
6.测试,即可出现输入用户名密码的对话框
在windows上只需要在路径上作出相应改变
AuthName "My Authorization Directory"
AuthType Basic
AuthUserFile c:/home/my.pass
Require valid-user
还要记住不能用#作注释,否则会出现错误
C:/Program Files/Apache Group/Apache2/htdocs/.htaccess: AuthName takes one argument, The authentication realm (e.g. "Members Only") |
|
|