Apache 多域名配置
多个域名直接指向对应的位置
环境
把两个域名应用在一台服务器中
test1.example.com -> /var/www/html/test1
test2.example.com -> /var/www/html/test2
步骤
添加并修改配置文档(test1)
复制
cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/test1.example.com.conf
修改
vim /etc/apache2/sites-available/test1.example.com.conf
<VirtualHost *:80>
# ServerName example.com
ServerName test1.example.com
# DocumentRoot /var/www/example.com/public_html
DocumentRoot /var/www/html/test1
<Directory /var/www/html/test1>
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
添加并修改配置文档(test2)
复制
cp /etc/apache2/sites-available/test1.example.com.conf /etc/apache2/sites-available/test2.example.com.conf
修改
vim /etc/apache2/sites-available/test2.example.com.conf
<VirtualHost *:80>
# ServerName example.com
ServerName test2.example.com
# DocumentRoot /var/www/example.com/public_html
DocumentRoot /var/www/html/test2
<Directory /var/www/html/test2>
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
启动配置文档
sudo a2ensite test1.example.com.conf
sudo a2ensite test2.example.com.conf
关闭默认配置文档
sudo a2dissite 000-default.conf
重启服务应用配置
systemctl reload apache2
测试
http://test1.example.com
http://test2.example.com
参考
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-18-04