{"id":1024,"date":"2013-05-04T05:05:39","date_gmt":"2013-05-04T11:05:39","guid":{"rendered":"http:\/\/blog.supportpro.com\/?p=1024"},"modified":"2025-04-28T05:09:56","modified_gmt":"2025-04-28T11:09:56","slug":"multiple-ssl-certificates-on-a-single-ip-using-apache","status":"publish","type":"post","link":"https:\/\/www.supportpro.com\/blog\/multiple-ssl-certificates-on-a-single-ip-using-apache\/","title":{"rendered":"Multiple SSL Certificates on a Single IP Using Apache"},"content":{"rendered":"<p>SNI ( Server Name Identification) allows you to host <a href=\"https:\/\/www.supportpro.com\/blog\/multiple-ssl-certificates-on-a-single-ip-using-nginx\/\">multiple SSL certificates on a single IP<\/a> address. Although, hosting several sites on a single virtual private server is possible with the use of virtual hosts, providing separate SSL certificates for each site traditionally required separate IP addresses. The process has now been simplified through the use of Server Name Indication (SNI), which sends a site visitor the certificate that matches the requested server name.<\/p>\n<p>Requirements<\/p>\n<p>1. Domain names should be registered in order to serve the certificates by SNI.<\/p>\n<p>2. Root Privileges to the server.<\/p>\n<p>3. Apache should already be installed and running<\/p>\n<p><!--more--><\/p>\n<p>Set up<\/p>\n<p>1. Create Your SSL Certificates<\/p>\n<p>For easy understanding, I will be working to create a server that hosts both example.com and example.org.<\/p>\n<p>The SSL certificate has 2 parts main parts: the certificate itself and the public key. We should create a directory for each virtual hosts SSL certificate.<\/p>\n<blockquote><p># mkdir -p \/etc\/apache2\/ssl\/example.com<br \/>\n# mkdir -p \/etc\/apache2\/ssl\/example.org<\/p><\/blockquote>\n<p>2. Activate the SSL Module<\/p>\n<p>The next step is to enable SSL.<\/p>\n<blockquote><p># sudo a2enmod ssl<\/p><\/blockquote>\n<p>Restart apache after that :<\/p>\n<blockquote><p># sudo service apache2 restart<\/p><\/blockquote>\n<p>3. Create a Self Signed SSL Certificate<\/p>\n<p>When we request a new certificate, we can specify how long the certificate should remain valid by changing the 365 to the number of days we prefer. As it stands this certificate will expire after one year.<\/p>\n<blockquote><p># sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout \/etc\/apache2\/ssl\/example.com\/apache.key out \/etc\/apache2\/ssl\/example.com\/apache.crt<\/p><\/blockquote>\n<p>we have now created both the self-signed SSL certificate and the server key that protects it, and placing both of them into the new directory.<\/p>\n<p>This command will prompt terminal to display a list of fields that need to be filled in.<\/p>\n<p>For the second (example.org) domain:<\/p>\n<blockquote><p># sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout \/etc\/apache2\/ssl\/example.org\/apache.keyout \/etc\/apache2\/ssl\/example.org\/apache.crt<\/p><\/blockquote>\n<p>4. Create the Virtual Hosts<\/p>\n<p>Once you have the certificates saved and ready, you can add in your information in the virtual host files. we can create two virtual host files to store virtual host information in separate files, copying the configuration from the default virtual host file.<\/p>\n<blockquote><p># sudo nano \/etc\/apache2\/sites-available\/example.com<br \/>\n# sudo nano \/etc\/apache2\/sites-available\/example.org<\/p><\/blockquote>\n<p>Open up each file and paste in the configuration below:<\/p>\n<p>The default configuration files offer a variety of useful directives and additional configuration options that you can add to the virtual host. However, the following information will provide the server everything it needs to set up multiple SSL certificates on one IP address.<\/p>\n<blockquote><p>&lt;VirtualHost *:80&gt;<br \/>\nServerAdmin webmaster@localhost<br \/>\nServerName example.com<br \/>\nDocumentRoot \/var\/www<\/p>\n<p>&lt;\/VirtualHost&gt;<\/p>\n<p>&lt;IfModule mod_ssl.c&gt;<br \/>\n&lt;VirtualHost *:443&gt;<\/p>\n<p>ServerAdmin webmaster@localhost<br \/>\nServerName example.com<br \/>\nDocumentRoot \/var\/www<\/p>\n<p># SSL Engine Switch:<br \/>\n# Enable\/Disable SSL for this virtual host.<br \/>\nSSLEngine on<\/p>\n<p># A self-signed (snakeoil) certificate can be created by installing<br \/>\n# the ssl-cert package. See<br \/>\n# \/usr\/share\/doc\/apache2.2-common\/README.Debian.gz for more info.<br \/>\n# If both key and certificate are stored in the same file, only the<br \/>\n# SSLCertificateFile directive is needed.<br \/>\nSSLCertificateFile \/etc\/apache2\/ssl\/example.com\/apache.crt<br \/>\nSSLCertificateKeyFile \/etc\/apache2\/ssl\/example.com\/apache.key<br \/>\n&lt;\/VirtualHost&gt;<\/p>\n<p>&lt;\/IfModule&gt;<\/p><\/blockquote>\n<p>5. Edit the ports.conf file<\/p>\n<p>The final step required to make sure that multiple certificates work on one VPS is to tell the server to listen on port 443.<\/p>\n<blockquote><p># sudo nano \/etc\/apache2\/ports.conf<\/p><\/blockquote>\n<p>Add the following lines to the apache ports configuration file:<\/p>\n<blockquote><p>NameVirtualHost *:80<br \/>\nNameVirtualHost *:443<\/p>\n<p>Listen 80<\/p>\n<p>&lt;IfModule mod_ssl.c&gt;<br \/>\n# If you add NameVirtualHost *:443 here, you will also have to change<br \/>\n# the VirtualHost statement in \/etc\/apache2\/sites-available\/default-ssl<br \/>\n# to<br \/>\n# Server Name Indication for SSL named virtual hosts is currently not<br \/>\n# supported by MSIE on Windows XP.<br \/>\nListen 443<br \/>\n&lt;\/IfModule&gt;<\/p>\n<p>&lt;IfModule mod_gnutls.c&gt;<br \/>\nListen 443<br \/>\n&lt;\/IfModule&gt;<\/p><\/blockquote>\n<p>6. Activate the Virtual Hosts<\/p>\n<blockquote><p># sudo a2ensite example.com<br \/>\n# sudo a2ensite example.org<\/p><\/blockquote>\n<p>7. Restart Apache<\/p>\n<blockquote><p># sudo service apache2 restart<\/p><\/blockquote>\n<p>You should now be able to access both sites, each with its own domain name and SSL certificate.<\/p>\n<p>You can view the sites both with and without the signed SSL certificates by typing in just the domain or the domain with the https prefix.<\/p>\n<p>If you require help, <a href=\"https:\/\/www.supportpro.com\/requestquote.php\">contact SupportPRO Server Admin<\/a><\/p>\n<p style=\"text-align: center;\"><!--HubSpot Call-to-Action Code --><span id=\"hs-cta-wrapper-9d590242-d641-4383-94b4-8cfd62f0af6b\" class=\"hs-cta-wrapper\"><span id=\"hs-cta-9d590242-d641-4383-94b4-8cfd62f0af6b\" class=\"hs-cta-node hs-cta-9d590242-d641-4383-94b4-8cfd62f0af6b\"><!-- [if lte IE 8]><\/p>\n\n\n\n\n\n<div id=\"hs-cta-ie-element\"><\/div>\n\n\n<![endif]--><a href=\"https:\/\/www.supportpro.com\/requestquote.php\"><img decoding=\"async\" id=\"hs-cta-img-9d590242-d641-4383-94b4-8cfd62f0af6b\" class=\"hs-cta-img\" style=\"border-width: 0px;\" src=\"https:\/\/no-cache.hubspot.com\/cta\/default\/2725694\/9d590242-d641-4383-94b4-8cfd62f0af6b.png\" alt=\"Server not running properly? Get A FREE Server Checkup By Expert Server Admins - $125 Value\" \/><\/a><\/span><script charset=\"utf-8\" src=\"https:\/\/js.hscta.net\/cta\/current.js\"><\/script><script type=\"text\/javascript\"> hbspt.cta.load(2725694, '9d590242-d641-4383-94b4-8cfd62f0af6b', {}); <\/script><\/span><!-- end HubSpot Call-to-Action Code --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>SNI ( Server Name Identification) allows you to host multiple SSL certificates on a single IP address. Although, hosting several sites on a single virtual private server is possible with&hellip;<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-1024","post","type-post","status-publish","format-standard","hentry","category-miscellaneous"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/1024","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/comments?post=1024"}],"version-history":[{"count":14,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/1024\/revisions"}],"predecessor-version":[{"id":14569,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/posts\/1024\/revisions\/14569"}],"wp:attachment":[{"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/media?parent=1024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/categories?post=1024"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.supportpro.com\/blog\/wp-json\/wp\/v2\/tags?post=1024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}