zoukankan      html  css  js  c++  java
  • 12、目录索引和身份验证/基于个人主页身份验证

    一、目录索引和身份验证

    1、把http服务的编码改为utf-8,把var/www/html目录下 设置不允许目录索引,允许局部配置

    [root@localhost html]#   vi   /etc/httpd/conf/httpd.conf

    按:进入命令行   ,再输入 /AddDefau,按回车
    看有AddDefaultCharset    ,如果没有,按 n 键 查找下一个
    改为   AddDefaultCharset  utf-8  ,如下图

    image

    同上面的操作

    :/AllowOverride 查找, 找到其中 <Directory "var/www/html">
    将下面的二个修改如下:
     Options   -Indexes   FollowSymLinks     (不允许目录索引)
     AllowOverride   All                               (允许局部配置)

    image

    (注意:

               全局配置:   写在   httpd.conf  文件

               局部配置:   写在   .htaccess    文件

               Options   -Indexes   FollowSymLinks   不允许目录索引        即是访问var/www/html目录,看不到里面的东西

                       Options   Indexes   FollowSymLinks    允许目录索引           访问var/www/html目录,可以遍历里面的东西

               AllowOverride   All         允许局部配置       即是var/www/html目录下 有.htaccess局部配置文件,就以这个里面设置为准

               AllowOverride   None      不允许局部配置   

    2、重启httpd服务,使配置生效

    [root@localhost html]#   service   httpd    restart
    停止 httpd:                                               [  确定  ]
    启动 httpd:                                               [  确定  ]

    还有另一种:  

    [root@localhost html]#  apachectl   restart

    3、分别创建lab 和  exam 目录,在其下创建1.txt 和2.txt

    [root@localhost html]#   cd    /var/www/html
    [root@localhost html]#   mkdir   lab   exam
    [root@localhost html]#    cd  lab
    [root@localhost lab]#      cat > 1.txt
    实验

    [root@localhost root]#    cd  /var/www/html/exam
    [root@localhost exam]#   cat   >  2.txt
    测试

    4、为exam配置局部配置文件

    [root@localhost exam]# cat  >  .htaccess
    Options    Indexes        (允许目录索引)

    5、测试  不允许目录索引 

    在浏览器输入http://192.168.170.4/lab/,有以下错误提示

    image

    在浏览器输入http://192.168.170.4/exam/,正常显示,证明exam目录下的局部配置文件生效

    image

    .

    6、如果想lab目录,要指定帐号和密码登录后 才能查看  (身份验证)

    [root@localhost exam]# cd   /var/www/html/lab
    [root@localhost lab]#  cat  >  .htaccess

    Options  Indexes

    AuthType  Basic
    AuthName  "teach"
    AuthUserFile   "/var/www/users"
    Require   valid-user

    [root@localhost lab]#   htpasswd   -c   /var/www/users   wang    (添加用户)
    New password:
    Re-type new password:
    Adding password for user wang


    [root@localhost lab]#  chown  apache:apache   /var/www/users     (加权限)

    测试:

    image

    image

    二、基于个人主页身份验证

    1、

    [root@localhost lab]# vi   /etc/httpd/conf/httpd.conf

    UserDir   disable       ( 这个把# 注释掉)

    UserDir   public_html   (这个去掉 # 注释)如下图:

    image

     

    [root@localhost lab]#  apachectl  restart

    [root@localhost lab]#  su  -  yanji
    [yanji@localhost yanji]$  mkdir  public_html
    [yanji@localhost yanji]$  cd   public_html
    [yanji@localhost public_html]$ cat  >  index.html
    yanji个人主页

    (即是 个人主页 就是 用户public_html   目录下的 index.html)

    这时候由于权限问题,会有下面错误

    image

    解决方案:给yanji 和 public_html 目录加权限

    [yanji@localhost public_html]$   chmod  701   .
    [yanji@localhost public_html]$  cd   /home/yanji
    [yanji@localhost yanji]$   chmod   701  .

    image


     

    至此,完成

  • 相关阅读:
    saltstack高效运维
    python与RPC服务
    01-08-01【Nhibernate (版本3.3.1.4000) 出入江湖】NHibernate中的一级缓存
    01-08-01【Nhibernate (版本3.3.1.4000) 出入江湖】NHibernate中的三种状态
    01-07-01【Nhibernate (版本3.3.1.4000) 出入江湖】并发控制
    01-06-01【Nhibernate (版本3.3.1.4000) 出入江湖】事务
    01-05-01-2【Nhibernate (版本3.3.1.4000) 出入江湖】立即加载实现--NHibernateUtil.Initialize()和添加fetch关键字的HQL查询
    01-05-01-1【Nhibernate (版本3.3.1.4000) 出入江湖】延迟加载及其class和集合(set、bag等)的Lazy属性配置组合对Get和Load方法的影响
    01-01-01【Nhibernate (版本3.3.1.4000) 出入江湖】配置文件
    【log4net】配置文件
  • 原文地址:https://www.cnblogs.com/weiapro/p/4759199.html
Copyright © 2011-2022 走看看