天天看点

linux apache 目录访问,linux上配置apache实现二级域名访问目录

在下面我们将实现利用www.test.mytest.com访问 根目录下面的test目录

这里以腾讯云为例子:

首先你得具备一个云主机 有一个公网ip

有一个主域名 www.mytest.com为例子

www.mytest.com已经解析到你的公网ip

添加记录

这里记录纸应该填写你的公网ip

linux apache 目录访问,linux上配置apache实现二级域名访问目录

这里添加记录大概10分钟即可使用该记录

找到你的apache配置文件

find / -name httpd.conf

打开该文件或者

vi $(find / -name httpd.conf)

添加

DocumentRoot /var/www/test

ServerName test.mytest.com

Options -Indexes +FollowSymlinks

AllowOverride All

Require all granted

或者

#开启url重写模式

RewriteEngine on

在网站根目录中.

htaccess填写

DocumentRoot /var/www/test

ServerName test.mytest.com

Options -Indexes +FollowSymlinks

AllowOverride All

Require all granted

填写完后

apachectl restart 重启apachectl

到 /var/www目录下创建一个目录test

在test中添加index.html

地址栏输入

www.test.mytest,com/index.html即可访问