Named virtual hosts are not enabled by default on an Amazon AMI. To enable them, edit /etc/httpd/conf/httpd.conf and uncomment line 991:
You can then begin adding your named virtual hosts in the /etc/httpd/conf.d/ directory. Below is an example of a named virtual host file:
<VirtualHost *:80> ServerAdmin email@example.com DocumentRoot /var/www/example.com ServerName example.com ServerAlias www.example.com ErrorLog /var/log/httpd/error_example_com.log CustomLog /var/log/httpd/access_example_com.log common </VirtualHost>
The difference between a named virtual host and an IP-based virtual host is that you need an additional IP address on your server for each virtual host you want to implement. Named virtual hosts come in handy when you only have 1 external IP address or if you want to host multiple websites on the same web server.