参考链接: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts

假设要将来自xxxx.com 的访问映射到 /var/www/xxxx.com

1
2
3
cd /etc/apache2/sites-available/
sudo cp 000-default.conf xxxx.com.conf
sudo vi xxxx.com.conf

xxxx.com.conf 的相应内容做一些修改,如下

1
2
3
4
5
6
7
8
<VirtualHost *:80>
ServerAdmin admin@xxxx.com
ServerName xxxx.com
ServerAlias www.xxxx.com
DocumentRoot /var/www/xxxx.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

继续执行命令

1
2
sudo a2ensite xxxx.com.conf
sudo service apache2 restart