===== Apache Server Name Indication (SNI) =====
{{tag>Linux Apache}}
This following are Apache configuration examples on how to implement SNI or domain name based virtual hosting. The following examples also include unique SSL certificates for each domain name.
**The two main requirements are;**
* **NameVirtualHost** enabled in the main Apache httpd.conf file.
* Unique **ServerName** for each site domain name each in their own VirtualHost section.
==== Apache General Config ====
[root@SERVER ~]# cat /etc/httpd/conf/httpd.conf
NameVirtualHost *:80
NameVirtualHost *:443
==== SITE1.COM Config ====
[root@SERVER ~]# cat /etc/httpd/conf.d/SITE1.COM.conf
ServerAdmin hostmaster@SITE1.COM
DocumentRoot /var/www/SITE1.COM
ServerName SITE1.COM
ServerAlias www.SITE1.COM
ErrorLog logs/SITE1.COM-error_log
TransferLog logs/SITE1.COM-access_log
CustomLog logs/SITE1.COM-custom_log common
ServerAdmin hostmaster@SITE1.COM
DocumentRoot /var/www/SITE1.COM
ServerName SITE1.COM
ServerAlias www.SITE1.COM
ErrorLog logs/SITE1.COM-ssl_error_log
TransferLog logs/SITE1.COM-ssl_access_log
CustomLog logs/SITE1.COM-ssl_custom_log common
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/WWW.SITE1.COM.crt
SSLCertificateKeyFile /etc/pki/tls/private/WWW.SITE1.COM.key
SSLCertificateChainFile /etc/pki/tls/certs/CA-ROOT.crt
#
# Rest of SSL config
#
==== DEMO.SITE2.COM Config ====
[root@SERVER ~]# cat /etc/httpd/conf.d/DEMO.SITE2.COM.conf
Redirect 301 / https://DEMO.SITE2.COM/
ServerAdmin hostmaster@DEMO.SITE2.COM
DocumentRoot /var/www/DEMO.SITE2.COM
ServerName DEMO.SITE2.COM
ErrorLog logs/DEMO.SITE2.COM-error_log
TransferLog logs/DEMO.SITE2.COM-access_log
CustomLog logs/DEMO.SITE2.COM-custom_log common
ServerAdmin hostmaster@DEMO.SITE2.COM
DocumentRoot /var/www/DEMO.SITE2.COM
ServerName DEMO.SITE2.COM
ErrorLog logs/DEMO.SITE2.COM-ssl_error_log
TransferLog logs/DEMO.SITE2.COM-ssl_access_log
CustomLog logs/DEMO.SITE2.COM-ssl_custom_log common
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/DEMO.SITE2.COM.crt
SSLCertificateKeyFile /etc/pki/tls/private/DEMO.SITE2.COM.key
SSLCertificateChainFile /etc/pki/tls/certs/CA-ROOT.crt
#
# Rest of SSL config
#
[root@SERVER ~]#