{"id":844,"date":"2015-03-03T23:33:32","date_gmt":"2015-03-04T04:33:32","guid":{"rendered":"http:\/\/xfloyd.net\/blog\/?p=844"},"modified":"2015-03-06T22:50:29","modified_gmt":"2015-03-07T03:50:29","slug":"multi-domain-ssl-setup-with-subject-alternative-names","status":"publish","type":"post","link":"https:\/\/xfloyd.net\/blog\/?p=844","title":{"rendered":"Multi-Domain SSL Setup with \u201cSubject Alternative Names\u201d"},"content":{"rendered":"<p>SSL Setup for multiple domains\/subdomains is different than single-domain or wildcard domain setup. There are 2-ways to setup this (as far as I know) \u2013 using\u00a0<a href=\"http:\/\/en.wikipedia.org\/wiki\/SubjectAltName\">Subject Alternative Names<\/a> and\u00a0<a href=\"http:\/\/en.wikipedia.org\/wiki\/Server_Name_Indication\">Server Name Indication (SNI)<\/a><\/p>\n<p>In this article, we will use \u201cSubject Alternative Names\u201d method.<\/p>\n<h2 id=\"use-cases\">Use Cases<\/h2>\n<p>This tutorial is intended for following types of use case. If you are trying to setup something else, please ignore this.<\/p>\n<h3 id=\"non-www-and-www-version-of-your-site\">non-www and www version of your site<\/h3>\n<ol>\n<li>example.com<\/li>\n<li>www.example.com<\/li>\n<\/ol>\n<p><!--more--><\/p>\n<h3 id=\"wildcard-all-subdomains-and-apexrootnaked-domain\">wildcard (all subdomains) and apex\/root\/naked domain<\/h3>\n<ol>\n<li>example.com<\/li>\n<li>*.example.com<\/li>\n<\/ol>\n<p>Please note that most wildcard SSL do not protect your root domain i.e. example.com<\/p>\n<h3 id=\"altogether-different-domains\">altogether different domains<\/h3>\n<ol>\n<li>example.com<\/li>\n<li>example.net<\/li>\n<li>google.com<\/li>\n<li>rtcamp.com<\/li>\n<li>www.example.com<\/li>\n<\/ol>\n<h2 id=\"process\">Process<\/h2>\n<p>Different companies offers different type of SSL certificates. They have different type of interfaces for CSR signing and certificate generation. So we will outline process on your server-side only (which should remain common across all Ubuntu server)<\/p>\n<h3 id=\"openssl-config-file\">OpenSSL Config File<\/h3>\n<h4 id=\"copy-openssl-conf\">Copy OpenSSL conf<\/h4>\n<p>By default, when you are are running OpenSSL commands, it is picking config from <code>\/etc\/ssl\/openssl.cnf<\/code>\u00a0file.<\/p>\n<p>Unless you are configuring only one certificate on your server, it\u2019s better to copy OpenSSL config file to website\u2019s cert folder:<\/p>\n<pre><code class=\"bash\">cp \/etc\/ssl\/openssl.cnf \/var\/www\/example.com\/cert\/example.com.cnf<\/code><\/pre>\n<h4 id=\"editing-config-file\">Editing Config File<\/h4>\n<p>Open\u00a0<code>\/var\/www\/example.com\/cert\/example.com.cnf<\/code><\/p>\n<p>Look for \u00a0<code>[ req ]<\/code> section. Find add uncomment following line:<\/p>\n<pre><code class=\"no-highlight\">req_extensions = v3_req<\/code><\/pre>\n<p>If you don\u2019t find a line like above, you can add one.<\/p>\n<p>This will make sure our next section <code>[ v3_req ]<\/code>\u00a0is read\/used.<\/p>\n<p>In <code>[ v3_req ]<\/code>\u00a0section, add following line:<\/p>\n<pre><code class=\"no-highlight\">subjectAltName = @alt_names<\/code><\/pre>\n<p>It will look like:<\/p>\n<pre><code class=\"no-highlight\">[ v3_req ]\r\n\r\n# Extensions to add to a certificate request\r\n\r\nbasicConstraints = CA:FALSE\r\nkeyUsage = nonRepudiation, digitalSignature, keyEncipherment\r\nsubjectAltName = @alt_names<\/code><\/pre>\n<p>Finally add a new section called <code>[\u00a0alt_names ]<\/code>\u00a0towards end of file listing all domain variation you are planning to use.<\/p>\n<pre><code class=\"no-highlight\">[ alt_names ]\r\nDNS.1 = www.example.com\r\nDNS.2 = example.com<\/code><\/pre>\n<p><strong>Note:<\/strong> I couldn\u2019t \u00a0find out whether we need to add domain used in common-name field again here. So I added it again here. Now in common-field, we use\u00a0<em>www.example.com<\/em> version \u2013 if SSL is for www and non-www versions of domains.<\/p>\n<p>Now you have your OpenSSL config file ready.<\/p>\n<h3 id=\"openssl-private-key--csr\">OpenSSL Private Key &amp; CSR<\/h3>\n<p>Make sure you are currently working in cert folder for your site:<\/p>\n<pre><code class=\"no-highlight\">cd \/var\/www\/example.com\/cert\/<\/code><\/pre>\n<h4 id=\"private-key\">Private Key<\/h4>\n<p>Run following command to generate private key. Do not use passphrase as nginx will use this private key.<\/p>\n<pre><code class=\"no-highlight\">openssl genrsa -out example.com.key 2048<\/code><\/pre>\n<h4 id=\"certificate-signing-request--csr-generation\">Certificate Signing Request \u2013 CSR generation<\/h4>\n<p>Next, we will generate CSR using private key above <strong>AND <\/strong>site-specific copy of OpenSSL config file.<\/p>\n<pre><code class=\"no-highlight\">openssl req -new -key example.com.key -out example.com.csr -config example.com.cnf<\/code><\/pre>\n<p>Please note <code>-config<\/code>\u00a0switch. If you forget it, your CSR won\u2019t include (Subject)\u00a0Alternative (domain) Names.<\/p>\n<h4 id=\"verify-csr\">Verify CSR<\/h4>\n<p>Since sending CSR and getting certificate is time consuming process, it\u2019s better to verify if CSR is generated correctly.<\/p>\n<p>Run following command:<\/p>\n<pre><code class=\"no-highlight\">openssl req -in example.com.csr -noout -text<\/code><\/pre>\n<p>You will see something like below in output. Please make sure you read highlighted area.<\/p>\n<pre><code class=\"no-highlight\">Certificate Request:\r\n    Data:\r\n        Version: 0 (0x0)\r\n        Subject: C=IN, ST=MH, L=PUNE, O=RTCAMP SOLUTIONS PRIVATE LIMITED., <strong>CN=www.example.com<\/strong>\/emailAddress=admin@example.com\r\n\t[...]\r\n            X509v3 Basic Constraints: \r\n                CA:FALSE\r\n            X509v3 Key Usage: \r\n                Digital Signature, Non Repudiation, Key Encipherment\r\n            X509v3 Subject Alternative Name: \r\n                <strong>DNS:www.example.com, DNS:example.com<\/strong>\r\n\t[...]<\/code><\/pre>\n<h3 id=\"submitting-csr-and-requesting-certificate\">Submitting CSR and Requesting certificate<\/h3>\n<p>Once you have CSR, the process of submitting it is online and often coupled with extra steps depending of certificate provider.<\/p>\n<p>You can refer to <a href=\"https:\/\/rtcamp.com\/wordpress-nginx\/tutorials\/ssl\/godaddy\/\">GoDaddy workflow<\/a> and <a href=\"https:\/\/rtcamp.com\/wordpress-nginx\/tutorials\/ssl\/thawte\/\">Thawte Workflow<\/a> here.<\/p>\n<p>Also, when you get certificate from provider, you can verify if its correct by <a href=\"https:\/\/rtcamp.com\/tutorials\/linux\/openssl-match-private-key-cert-csr\/\">using this article<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SSL Setup for multiple domains\/subdomains is different than single-domain or wildcard domain setup. There are 2-ways to setup this (as far as I know) \u2013 using\u00a0Subject Alternative Names and\u00a0Server Name Indication (SNI) In this article, we will use \u201cSubject Alternative Names\u201d method. Use Cases This tutorial is intended for following types of use case. If [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/844"}],"collection":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=844"}],"version-history":[{"count":2,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/844\/revisions"}],"predecessor-version":[{"id":846,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/844\/revisions\/846"}],"wp:attachment":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=844"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=844"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}