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. 开发中常用linux命令

    1.创建目录mkdir 创建目录命令,常用的参数-p,递归创建目录 [root@web01 ~]# mkdir /data [root@web01 ~]# mkdir /data/a/b mkdir: ...

  2. springboot2.x自定义拦截把static静态文件给拦截的坑

    新人新帖,喷后请指正,谢谢 1.王中王,坑中坑 和很多人一样,我在springboo自定义配置登录拦截的时候,写一个WebConfig类继承WebMvcConfigureAdapter,重写AddRe ...

  3. [no_perms] Private mode enable, only admin can publish this module

    在使用npm publish是出现了错误: npm ERR! code E403 npm ERR! 403 Forbidden - PUT https://registry.npm.taobao.or ...

  4. CF461B Appleman and Tree

    CF461B Appleman and Tree 传送门 一道比较容易的树形DP. 考虑用\(dp[i][1]\)代表将\(i\)分配给\(i\)的子树内黑点的方案数,\(dp[i][0]\)代表将\ ...

  5. 详解手把手Maven搭建SpringMVC+Spring+MyBatis框架(超级详细版)

    转载(https://www.jb51.net/article/130560.htm) SSM(Spring+SpringMVC+Mybatis),目前较为主流的企业级架构方案.标准的MVC设计模式, ...

  6. Centos7之搜索命令locate

    locate命令[1] 1.#locate命令 所搜索的后台数据库 2.updatedb 更新数据库 3.操作 [root@localhost ~]# ls 222  anaconda-ks.cfg ...

  7. PHP处理SOAP

    1.获取functions try { $client = new SoapClient("http://www.fangbei.org/services/inquiryTracingAnd ...

  8. [转帖]springboot2.0配置连接池(hikari、druid)

    springboot2.0配置连接池(hikari.druid) 原文链接:https://www.cnblogs.com/blog5277/p/10660689.html 原文作者:博客园--曲高终 ...

  9. 移动端可视化框架antv f2出现两个legend选项

    前天遇到个坑,把我给坑死了 ,在帮朋友做一个微信公众号的项目,使用的vue全家桶,有个模块需要用到数据可视化展现,之前做项目的时候用过antv,比较熟悉,因为是移动端的项目,所以用的是antv f2这 ...

  10. 分享大麦UWP版本开发历程-01.响应式轮播顶部焦点图

    话说有一天,临近下班无心工作,在网上看各种文章,阅读到了一篇名为<聊聊大麦网UWP版的首页顶部图片联动效果的实现方法>(传递:http://www.cnblogs.com/hippieZh ...