Apache httpd 2.4 alias 别名配置

Web网站别名配置是被经常使用的一个特性。这个功能实际上是为站点URI定义一个路径映射关系,其配置和使用也较为简单。以下是基于CentOS 7下实现alias的别名配置,供大家参考。

配置示例

[root@centos7-web ~]# more /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 

[root@centos7-web ~]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 19 2015 21:43:13

###关闭selinux
[root@centos7-web ~]# setenforce 0

[root@centos7-web ~]# vim /etc/httpd/conf/httpd.conf

    #
    # Alias: Maps web paths into filesystem paths and is used to
    # access content that does not live under the DocumentRoot.
    # Example:
    # Alias /webpath /full/filesystem/path
    #
    # If you include a trailing / on /webpath then the server will
    # require it to be present in the URL.  You will also likely
    # need to provide a <Directory> section to allow access to
    # the filesystem path.

Alias /bbs "/forum/htdocs"

<Directory "/forum/htdocs">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Require all granted
</Directory>
上述别名的配置,就是说当你基于你的站点访问http://www.yourdoamin.com/bbs目录下的文件时,会直接从服务器/forum/htdocs目录下访问对应的文件。

[root@centos7-web ~]# systemctl reload httpd
[root@centos7-web ~]# mkdir -pv /forum/htdocs/
mkdir: created directory ‘/forum/htdocs/’
[root@centos7-web ~]# echo "This is a alias path test.">>/forum/htdocs/index.html

[root@centos7-web ~]# curl http://localhost/bbs/index.html
This is a alias path test.

如果alias路径中指定的尾部目录斜线,如下,应两者匹配
Alias /bbs/ "/forum/htdocs/"
<Directory "/forum/htdocs/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Require all granted
</Directory>

DBA牛鹏社(SQL/NOSQL/LINUX)

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值