首先在域名服务商后台添加一个二级域名解析

1.Copy the default virtual host file called 000-default.conf contents to the new virtual host files like below

cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/heavenshappiness.conf

2.编辑二级域名虚拟主机的配置文件

nano /etc/apache2/sites-available/heavenshappiness.conf
ServerName heavenshappiness.wateryaml.cn
DocumentRoot /var/www/html1

html是事先要新建好的一个存放二级域名网站内容的文件夹

3.Enable virtual host configuration files

a2ensite heavenshappiness.conf
systemctl restart apache2