【Apache】尝试使用Alias功能
首先
我確實試著改變過去的Apache DocumentRoot,但現在我使用Alias(別名)的方式,似乎可以在不改變DocumentRoot的情況下,讓位於完全不同目錄下的文件,看起來就像是放在DocumentRoot的子目錄下一樣。
前提 – 前提条件
假设您已经根据以下文章所构建的环境。
-
- Windows10にVagrantをを入れてCentOS7をインストールしよう(1、2、3、4、5、6)
- ローカルでLAMP環境を構築しよう(0、1、4)
使用工具
- Tera Term
操作步骤
1. 重新写入设置文件
2. 创建用于进行操作确认的文件
3. 对指定的 DocumentRoot 文件夹授予权限
我们试试看
1. 修改设置文件
当你在/etc/httpd/conf/httpd.conf文件中搜索”Alias”时,会找到如下注释。
#
# 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: 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 /hoge "/hoge/hoge"
<Directory "/hoge/hoge">
Require all granted
</Directory>
如果有追加记录,就重新启动Apache。
systemctl restart httpd
2. 创建一个用于动作确认的文件
请按照以下方式在根目录下创建文件。
.
├── hoge
│ └── hoge
│ └── index.html
请在index.html中输入适当的文字并保存。
vi /hoge/hoge/index.html
3. 在指定的DocumentRoot文件夹上授予权限
使用下面的命令,将创建的文件夹和文件的所有者设置为apache。
chown apache:apache /hoge/hoge/index.html
通过以下命令授予权限。
chmod 755 /hoge/hoge/index.html
请确认Vagrantfile中config.vm.network设置的私有网络的IP地址。
在这里我们假设它为”192.168.33.10″。
请在浏览器中输入以下地址。
http://192.168.33.10/hoge/index.html
('index.html'は省略可)
如果您可以在浏览器中确认已保存在index.html的字符串,那就完成了。
顺便说一句
Alias可以设置多个选项。
#
# 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 /hoge "/hoge/hoge"
<Directory "/hoge/hoge">
Require all granted
</Directory>
Alias /foo "/foo/foo"
<Directory "/foo/foo">
Require all granted
</Directory>
按照下面的方式创建文件夹和文件:
/foo/foo/index.html
请尝试访问以下网址:
http://192.168.33.10/hoge/index.html
http://192.168.33.10/foo/index.html
请参考以下网站
エイリアス(Alias)
如何在Apache中公开不是文档根目录的目录
Apache显示403 Forbidden错误时的5个检查点
相关页面
让我们在Windows10上安装Vagrant并安装CentOS7。
1. 从安装Vagrant到设置Vagrantfile
2. 操作虚拟机
3. 使用密钥登录WinSCP和Tera Term
4. 使用root用户密码登录WinSCP和Tera Term
5. 安装zip/unzip
6. 在Vagrant中分发虚拟环境
在本地搭建LAMP环境。
0. 准备工作
1. 安装 Apache
4. 停止防火墙等
中文:亚帕奇
让我们尝试更改 DocumentRoot
让我们尝试使用 Alias
让我们尝试使用 VirtualHost
推荐的参考书
了解Apache的实际构建与运维(Software Design plus)
闲话不说
最近我的热衷是《喷射战士》。
我为此入迷到购买了专用的Switch游戏机…
大家也一定要试试看!