前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Apache httpd 2.4 alias 别名配置

Apache httpd 2.4 alias 别名配置

作者头像
Leshami
发布2018-08-06 10:49:55
1.7K0
发布2018-08-06 10:49:55
举报
文章被收录于专栏:乐沙弥的世界乐沙弥的世界

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

配置示例

代码语言:javascript
复制
[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>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017年11月14日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 配置示例
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档