Apache的目录属性

Apache的目录属性

前言

我们之前见过了Apache的工作模式,现在我们来瞧瞧这个目录属性,那么什么是目录属性呢?我们继续使用刚刚的环境。并开启一台win10虚拟机。

目录属性

目录的权限设置使用<Directory 目录路径>和< /Directory > 这对语句为主目录或虚拟目录设置权限。它们是一-对容器语句,必须成对出现,它们之间封装的是具体的设置目录权限语句,这些语句仅对被设置目录及其子目录起作用。

目录属性的参数

参数 作用
Options 设置在特定目录使用哪些特性
AllowOverride 允许存在于htaccess文件中的指令类型
Require 设置目录的访问控制
Indexes 当用户访问该目录时,但没有指定要访问哪个文件,而且目录下不存在默认网页时,返回目录中的文件和子目录列表
MultiViews 内容协商的多重视图,Apache的一 个智能特性。当访问目录中不存在的对象时
ExecCGI 允许在该目录下执行CGI脚本
FollowSymLinks 在该目录下允许文件系统使用符号连接
Includes 允许服务器端包含功能
IncludesNoExec 允许服务器端包含功能,但禁止执行CG
All 包含除了MultiViews之外所有特性,如果没有Options语句,默认为All

实验步骤

1.查看目录属性

[root@localhost bin]# vim /etc/httpd.conf
DocumentRoot "/usr/local/httpd/htdocs"
<Directory "/usr/local/httpd/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

2.查看站点里面的文件,并关闭防火墙

[root@localhost bin]# cd /usr/local/httpd/htdocs/
[root@localhost htdocs]# ls
index.html
[root@localhost htdocs]# cat index.html 
<html><body><h1>It works!</h1></body></html>
[root@localhost htdocs]# systemctl stop firewalld 
[root@localhost htdocs]# setenforce 0

3.在win10主机里面测试

在这里插入图片描述

4.将index.html换成a.html

[root@localhost htdocs]# mv index.html a.html
[root@localhost htdocs]# ls
a.html
[root@localhost htdocs]# touch b.html c.html d.html
[root@localhost htdocs]# ls
a.html  b.html  c.html  d.html

在win10主机中查看一下结果

在这里插入图片描述

在这里插入图片描述

5.将/etc/passwd建立一个连接到站点目录下

[root@localhost htdocs]# ln -s /etc/passwd ./
[root@localhost htdocs]# ls
a.html  b.html  c.html  d.html  passwd

在win10主机中查看

在这里插入图片描述

在这里插入图片描述

实验总结

我们可以通过Apache的目录属性的特点,将服务器的资源以这样的一种形式分享给别人,节省了不少资源,而且还省时省事。

发布了95 篇原创文章 · 获赞 39 · 访问量 6139

猜你喜欢

转载自blog.csdn.net/double_happy111/article/details/103618588