Httpd服务入门知识-Httpd服务常见配置案例之实现用户家目录的http共享

                                                作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.实现用户家目录的http共享前提

在配置家目录共享的2个前提是:
  基于模块mod_userdir.so实现
  SELinux: http_enable_homedirs 其中userdir模块默认是动态在家的,而selinux我们一般在内外情况下是禁用的:
  [root@node101.yinzhengjie.org.cn ~]# httpd -M | grep userdir
  userdir_module (shared)
  [root@node101.yinzhengjie.org.cn ~]#
  [root@node101.yinzhengjie.org.cn ~]# getenforce
  Disabled
  [root@node101.yinzhengjie.org.cn ~]#
  [root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf.d/userdir.conf      #该配置文件时官方单独抽出来配置用户家目录共享的哟~
  <IfModule mod_userdir.c>
    UserDir disabled            #虽然userdir模块被加载了,但这里却被官方显示禁用了,我们可以添加一个"#"号注释它,这样默认就是启用该功能的。
  </IfModule>
  <Directory "/home/*/public_html">
    AllowOverride FileInfo AuthConfig Limit Indexes
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require method GET POST OPTIONS
  </Directory>
  [root@node101.yinzhengjie.org.cn ~]#

二.配置用户家目录以http方式共享实战

1>.准备数据

[root@node101.yinzhengjie.org.cn ~]# su - yinzhengjie
Last login: Sat Nov :: CST from 172.30.1.101 on pts/
[yinzhengjie@node101.yinzhengjie.org.cn ~]$
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ ll
total
[yinzhengjie@node101.yinzhengjie.org.cn ~]$
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ mkdir public_html
[yinzhengjie@node101.yinzhengjie.org.cn ~]$
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ echo "尹正杰到此一游" > public_html/index.html    #会自动创建一个权限为644的文件。
[yinzhengjie@node101.yinzhengjie.org.cn ~]$
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ ll
total
drwxrwxr-x yinzhengjie yinzhengjie Dec : public_html
[yinzhengjie@node101.yinzhengjie.org.cn ~]$
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ cat public_html/index.html
尹正杰到此一游
[yinzhengjie@node101.yinzhengjie.org.cn ~]$
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ setfacl -m u:apache:x /home/yinzhengjie      #默认其它用户是无权限访问"yinzhengjie"用户的家目录的,因此我们需要显式的添加一条ACL规则来允许apache对家目录有执行权限即可(有了执行权限用户就可以切换到该目录)。
[yinzhengjie@node101.yinzhengjie.org.cn ~]$
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ getfacl /home/yinzhengjie
getfacl: Removing leading '/' from absolute path names
# file: home/yinzhengjie
# owner: yinzhengjie
# group: yinzhengjie
user::rwx
user:apache:--x
group::---
mask::--x
other::--- [yinzhengjie@node101.yinzhengjie.org.cn ~]$
[yinzhengjie@node101.yinzhengjie.org.cn ~]$ exit
logout
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#

2>.修改httpd的配置文件

[root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf.d/userdir.conf      #查看默认的配置文件
<IfModule mod_userdir.c>
UserDir disabled
</IfModule>
<Directory "/home/*/public_html">
AllowOverride FileInfo AuthConfig Limit Indexes
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Require method GET POST OPTIONS
</Directory>
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# vim /etc/httpd/conf.d/userdir.conf               #默认的配置文件需要修改
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf.d/userdir.conf
<IfModule mod_userdir.c>
UserDir public_html          #如果没有显式指定"UserDir disabled"切userdir模块已经被动态加载的话默认是启用该功能的,我们这里指定只允许访问用户家目录的"public_html"目录。
</IfModule>
<Directory "/home/yinzhengjie/public_html">
Require all granted          #我们只对"/home/yinzhengjie/public_html"目录进行共享
</Directory>
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# httpd -t
Syntax OK
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# systemctl reload httpd
[root@node101.yinzhengjie.org.cn ~]#

3>. 访问测试

  在客户端浏览器只需要输入"http://node101.yinzhengjie.org.cn/~yinzhengjie/"就可以访问到"/home/yinzhengjie/public_html/"目录下的数据啦,如下图所示。

三.添加验证的方式才能访问httpd配置的家目录

1>.根据上面演示的案例修改httpd的配置文件

[root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf.d/userdir.conf
<IfModule mod_userdir.c>
UserDir public_html
</IfModule>
<Directory "/home/yinzhengjie/public_html">
AuthType Basic
AuthName "Welecon to Login"
AuthUserFile "/etc/httpd//conf.d/httpdpasswd"
Require user jason  
</Directory>
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat /etc/httpd//conf.d/httpdpasswd
jason:$apr1$fnoHrDaP$Q0ZGtsOj9D4W3xHzIKm9E/
jay:{SHA}o78nbN18sxTgXokaJRMEYOxV5b8=
jerry:$apr1$NC0Az6Ga$2ers2ZQZttbW.DPNrie.n0
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# systemctl reload httpd
[root@node101.yinzhengjie.org.cn ~]#

2>.使用jason用户登录测试成功

  输入正确的用户名和密码就可以看到具体的内容,而且服务器会有相应的日志记录,如下图所示。

3>.使用jerry用户或者jay用户尽管输入正确的密码均会登录失败

Httpd服务入门知识-Httpd服务常见配置案例之实现用户家目录的http共享的更多相关文章

  1. Httpd服务入门知识-Httpd服务常见配置案例之虚拟主机

    Httpd服务入门知识-Httpd服务常见配置案例之虚拟主机 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.虚拟主机实现方案 1>.Apache httpd 有三种实现虚 ...

  2. Httpd服务入门知识-Httpd服务常见配置案例之Apache的工作做状态status页面

    Httpd服务入门知识-Httpd服务常见配置案例之Apache的工作做状态status页面 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.status功能概述 status页 ...

  3. Httpd服务入门知识-Httpd服务常见配置案例之ServerSignature指令选项

    Httpd服务入门知识-Httpd服务常见配置案例之ServerSignature指令选项 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.ServerSignature指令概述 ...

  4. Httpd服务入门知识-Httpd服务常见配置案例之定义路径别名

    Httpd服务入门知识-Httpd服务常见配置案例之定义路径别名 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.   一.创建测试数据 [root@node101.yinzhengj ...

  5. Httpd服务入门知识-Httpd服务常见配置案例之设定默认字符集

    Httpd服务入门知识-Httpd服务常见配置案例之设定默认字符集 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.查看生产环境中使用的字符集案例 1>.查看腾讯设置的默认 ...

  6. Httpd服务入门知识-Httpd服务常见配置案例之日志设定

    Httpd服务入门知识-Httpd服务常见配置案例之日志设定 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.日志类型 [root@node101.yinzhengjie.org ...

  7. Httpd服务入门知识-Httpd服务常见配置案例之基于客户端来源地址实现访问控制

    Httpd服务入门知识-Httpd服务常见配置案例之基于客户端来源地址实现访问控制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Options  1>.OPTIONS指 ...

  8. Httpd服务入门知识-Httpd服务常见配置案例之基于用户账号实现访问控制

    Httpd服务入门知识-Httpd服务常见配置案例之基于用户账号实现访问控制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.基于用户的访问控制概述 认证质询: WWW-Auth ...

  9. Httpd服务入门知识-Httpd服务常见配置案例之定义站点主页面及错误页面配置

    Httpd服务入门知识-Httpd服务常见配置案例之定义站点主页面及错误页面配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.定义站点主页面 [root@node101.yi ...

随机推荐

  1. haproxy 配置文件详解 之 defaults

    配置示例: defaults mode http retries timeout connect 10s timeout client 20s timeout server 30s timeout c ...

  2. centos删除指定名称的进程

    vim kill_process.sh ----------------------------------- if [ "$1" = "" ]; then e ...

  3. Python内网渗透扫描器Ladon

    Ladon Scanner For Python PyLadon 目前python版功能较少,无论在Windows还是Linux系统性能以及速度均也比不上Ladon.exe 唯一的优点是跨平台,后续会 ...

  4. Lab_1:练习4——分析bootloader加载ELF格式的OS的过程

    一.实验内容 通过阅读bootmain.c,了解bootloader如何加载ELF文件.通过分析源代码和通过qemu来运行并调试bootloader&OS, bootloader如何读取硬盘扇 ...

  5. switch/case/default中的雷区

    switch的语法如下: switch(表达式){ case常量表达式1: 语句1;break; case常量表达式2: 语句2;break; - case常量表达式n: 语句n;break; def ...

  6. SQL系列(十)—— 联结(join)

    在数据库设计中,基本上都是根实体ER关系和范式设计多张表.这样更能设计出更合理.紧凑的表结构,提高有效数据存储,数据的管理维护更简便,也提高了库表的伸缩性. 但是事物总是平衡的,在很多场景中单张表的数 ...

  7. InstantiationAwareBeanPostProcessor 分析

    Cglib之Enhancer创建动态代理https://blog.csdn.net/yaomingyang/article/details/82762697 https://blog.csdn.net ...

  8. MySQL数据类型之BLOB与TEXT及其最大存储限制

    https://blog.csdn.net/q3dxdx/article/details/51014357 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.n ...

  9. 2、Vue构造器和扩展

    1.VUE构造器简介 VUE构造器是一个非常重要的语法. 每个Vue.js应用都是通过构造函数Vue创建一个根实例. New了Vue对象,然后调用了这个vue对象的构造器,并向构造器传入了数据. 在实 ...

  10. .net core使用ocelot---第二篇 身份验证

    简介原文链接      .net core使用ocelot---第一篇 简单使用 接上文,我将继续介绍使用asp.net core 创建API网关,主要介绍身份验证(authentication )相 ...