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

时间:2023-12-14 09:41:38

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

                                                作者:尹正杰

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

 

一.创建测试数据

[root@node101.yinzhengjie.org.cn ~]# mkdir -pv /data/downloads/
mkdir: created directory ‘/data’
mkdir: created directory ‘/data/downloads/’
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cp -a /etc/sysconfig/network-scripts/ /data/downloads/
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# ll /data/downloads/network-scripts/ | wc -l [root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]#

二.编辑httpd的配置文件

[root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf  | grep ServerRoot
ServerRoot "/etc/httpd"
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# egrep -v "^ *#|^$" /etc/httpd/conf/httpd.conf | grep IncludeOptional
IncludeOptional conf.d/*.conf
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# cat /etc/httpd/conf.d/alias.conf
<Directory "/data/downloads/network-scripts">
Options Indexes FollowSymLinks
Require all granted
</Directory>
alias /netScript /data/downloads/network-scripts      #千万要注意,"/netScript"前面的"/"别忘记写了哟~,当客户端访问"/netScript"就会自动跳转到"/data/downloads/network-script"目录下去找index.html,若没有index.html文件就会遵守咱们配置的Options指令,会列出所有文件包括链接文件哟~
[root@node101.yinzhengjie.org.cn ~]#
[root@node101.yinzhengjie.org.cn ~]# systemctl reload httpd
[root@node101.yinzhengjie.org.cn ~]#

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