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

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

这里以腾讯云为例子:

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

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

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

添加记录

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

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

找到你的apache配置文件

find / -name httpd.conf

打开该文件或者

vi $(find / -name httpd.conf)

添加

<VirtualHost *:80>
DocumentRoot /var/www/test
ServerName test.mytest.com
<Directory "/var/www/test">
Options -Indexes +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

或者

 #开启url重写模式

RewriteEngine on
 
 
在网站根目录中. htaccess填写
 

<VirtualHost *:80>
DocumentRoot /var/www/test
ServerName test.mytest.com
<Directory "/var/www/test">
Options -Indexes +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

填写完后

apachectl restart 重启apachectl

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

在test中添加index.html

地址栏输入

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

猜你喜欢

转载自www.cnblogs.com/webcyh/p/11262168.html