Apache配置讲解——用户认证
2017-01-01 18:04
239 查看
有时候我们有这样的需求:有一个网站,其中一个目录只有你自己或者管理员才能看到的,不想让别人去访问,而且,还想在网站去展示,因为方便自己访问,这时候,有必要去做一个用户认证。也就是当你输入用户名和密码之后,只有输入正确了才可以去访问。
## 假如网站下有abc目录,目录有个文件,正常的话,可以访问
[root@aminglinux www]# mkdir abc
[root@aminglinux www]# cp /etc/passwd abc/123.txt
## 但比如说我们不想让别人访问网站下的abc目录,这时要做用户认证,编辑虚拟主机配置文件
[root@aminglinux www]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
<Directory /data/www/abc>
AllowOverride AuthConfig
AuthName "auth-admin"
AuthType Basic
AuthUserFile /data/.htpasswd
require valid-user
</Directory>
[root@aminglinux www]# /usr/local/apache2/bin/apachectl -t
Syntax OK
[root@aminglinux www]# /usr/local/apache2/bin/apachectl graceful
## 创建密码文件
[root@aminglinux www]# /usr/local/apache2/bin/htpasswd -c /data/.htpasswd wyy
New password:
Re-type new password:
Adding password for user wyy
## 查看生成的密码
[root@aminglinux www]# cat /data/.htpasswd
wyy:U6opizopWbwsg
## 查看帮助文档
[root@aminglinux ~]# /usr/local/apache2/bin/htpasswd --help
-c Create a new file.
-n Don't update file; display results on stdout.
-m Force MD5 encryption of the password.
-d Force CRYPT encryption of the password (default).
-p Do not encrypt the password (plaintext).
-s Force SHA encryption of the password.
-b Use the password from the command line rather than prompting for it.
-D Delete the specified user.
# 再次创建用户,则不需要-c创建密码文件,否则会覆盖
[root@aminglinux ~]# /usr/local/apache2/bin/htpasswd -m /data/.htpasswd wyy1
New password:
Re-type new password:
Adding password for user wyy1
# 修改配置文件测试语法
[root@aminglinux ~]# /usr/local/apache2/bin/apachectl -t
Syntax OK
#重启
[root@Lx ~]#/usr/local/apache2/bin/apachectl restart
## 这时候呢,再访问这个abc目录话,就需要输入用户名与密码
## 假如网站下有abc目录,目录有个文件,正常的话,可以访问
[root@aminglinux www]# mkdir abc
[root@aminglinux www]# cp /etc/passwd abc/123.txt
## 但比如说我们不想让别人访问网站下的abc目录,这时要做用户认证,编辑虚拟主机配置文件
[root@aminglinux www]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
<Directory /data/www/abc>
AllowOverride AuthConfig
AuthName "auth-admin"
AuthType Basic
AuthUserFile /data/.htpasswd
require valid-user
</Directory>
[root@aminglinux www]# /usr/local/apache2/bin/apachectl -t
Syntax OK
[root@aminglinux www]# /usr/local/apache2/bin/apachectl graceful
## 创建密码文件
[root@aminglinux www]# /usr/local/apache2/bin/htpasswd -c /data/.htpasswd wyy
New password:
Re-type new password:
Adding password for user wyy
## 查看生成的密码
[root@aminglinux www]# cat /data/.htpasswd
wyy:U6opizopWbwsg
## 查看帮助文档
[root@aminglinux ~]# /usr/local/apache2/bin/htpasswd --help
-c Create a new file.
-n Don't update file; display results on stdout.
-m Force MD5 encryption of the password.
-d Force CRYPT encryption of the password (default).
-p Do not encrypt the password (plaintext).
-s Force SHA encryption of the password.
-b Use the password from the command line rather than prompting for it.
-D Delete the specified user.
# 再次创建用户,则不需要-c创建密码文件,否则会覆盖
[root@aminglinux ~]# /usr/local/apache2/bin/htpasswd -m /data/.htpasswd wyy1
New password:
Re-type new password:
Adding password for user wyy1
# 修改配置文件测试语法
[root@aminglinux ~]# /usr/local/apache2/bin/apachectl -t
Syntax OK
#重启
[root@Lx ~]#/usr/local/apache2/bin/apachectl restart
## 这时候呢,再访问这个abc目录话,就需要输入用户名与密码
相关文章推荐
- apache 配置文件讲解
- apache常用配置文件讲解
- 详细讲解Apache主配置文件
- Ubuntu下Apache2多站点配置实例讲解
- 配置默认主机,Apache用户认证,域名跳转,Apache访问日志,访问日志
- apache https ssl配置详细步骤讲解
- apache https配置详细步骤讲解
- Apache用户认证、域名跳转、配置访问日志
- JDK+apache_2.0.47+tomcat-5.0.19组合配置(二)
- Apache 简介及基本配置
- 配置 Apache 实现禁止图片盗链~
- Windows2000 server和windows 2003下的Apache2.0.50与Tomcat5.0.27的整合配置方法
- Struts-config.xml配置文件讲解(一)
- Apache + Jboss3.0.7 + Tomcat4.1.x (for win2000 pro)配置
- Apache Tomcat服务器配置基础
- log4j的配置文件讲解
- Windows 环境下的 PHP5 与 Apache 服务器的配置
- Windows 环境下的PHP5 与 Apache 服务器的配置
- PHP4.0+APACHE2.0+MYSQL4.0配置方法
- 也谈win2000下tomcat&apache的配置