
{"id":3299,"date":"2021-05-29T23:32:23","date_gmt":"2021-05-29T23:32:23","guid":{"rendered":"https:\/\/blog.gordonbuchan.com\/blog\/?p=3299"},"modified":"2022-04-24T20:16:46","modified_gmt":"2022-04-24T20:16:46","slug":"web-presence-step-by-step-chapter-17-using-subdomains-to-host-multiple-websites-under-a-single-domain-name","status":"publish","type":"post","link":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/2021\/05\/29\/web-presence-step-by-step-chapter-17-using-subdomains-to-host-multiple-websites-under-a-single-domain-name\/","title":{"rendered":"Web presence step by step Chapter 17: Using subdomains to host multiple websites under a single domain name"},"content":{"rendered":"\n<p>Previous step Chapter 16: <a href=\"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/2021\/05\/19\/web-presence-step-by-step-chapter-16-using-a-script-to-automate-the-creation-of-a-virtual-host-on-an-apache-web-server\/\">Using a script to automate the creation of a virtual host on an Apache web server<\/a><br>Next step: Chapter 18: <a href=\"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/2022\/04\/24\/web-presence-step-by-step-chapter-18-installing-virtualbox-on-a-computer-running-windows-to-host-linux-as-a-virtual-machine-vm-guest\/\">Installing VirtualBox on a computer running Windows to host Linux as a virtual machine (VM) guest<\/a><\/p>\n\n\n\n<p>Web presence step by step is a series of posts that show you to how to build a web presence.<\/p>\n\n\n\n<p>In this post, we learn how to declare multiple subdomain names under a single domain name for use as virtual host names, for multiple separate websites.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Understanding virtual hosts and their relation to domain and subdomain names<\/h1>\n\n\n\n<p>A shared LAMP web server can host multiple websites, or \u201cvirtual hosts,\u201d named after domain and subdomain names.<\/p>\n\n\n\n<p>You may wish to host a web-based application like MyBB or Nextcloud as its own website, rather than as a subdirectory of an existing website, without purchasing an additional domain name.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"711\" src=\"https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/image-20-1024x711.png\" alt=\"\" class=\"wp-image-3379\" srcset=\"https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/image-20-1024x711.png 1024w, https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/image-20-300x208.png 300w, https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/image-20-768x533.png 768w, https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/image-20.png 1061w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<p>Multiple subdomains can be hosted on the same web server, or on different web servers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The bare domain and the www subdomain<\/h2>\n\n\n\n<p>A virtual host can be identified by a \u201cbare\u201d domain name like \u201cwebpresencestepbystep.com,\u201d or by a subdomain name, like \u201cwww.webpresencestepbystep.com\u201d &#8212; by convention, the www subdomain prefix points to the same content as the \u201cbare\u201d domain name.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Additional subdomains like \u201ccommunity\u201d and \u201cmedia\u201d<\/h2>\n\n\n\n<p>Additional subdomain names can be declared like \u201ccommunity.webpresencestepbystep.com\u201d and \u201cmedia.webpresencestepbystep.com\u201d \u2013 these subdomains can point to separate websites on the same web server, or on different web servers.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Understanding domain and subdomain names and their relation to Domain Name System (DNS) zone files<\/h1>\n\n\n\n<p>As we can see in the DNS zone for the domain, the host names &#8220;@&#8221; (&#8220;bare domain&#8221;) and &#8220;community&#8221; are A declarations associated with the IP address of web server A.<\/p>\n\n\n\n<p>The host name &#8220;www&#8221; is a CNAME declaration associated with the host name &#8220;@&#8221; so implicitly is associated with the IP address of web server A.<\/p>\n\n\n\n<p>The host name &#8220;media&#8221; is an A declaration associated with the IP address of web server B.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"797\" src=\"https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/Screenshot-from-2021-05-29-15-14-49-1024x797.png\" alt=\"\" class=\"wp-image-3306\" srcset=\"https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/Screenshot-from-2021-05-29-15-14-49-1024x797.png 1024w, https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/Screenshot-from-2021-05-29-15-14-49-300x234.png 300w, https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/Screenshot-from-2021-05-29-15-14-49-768x598.png 768w, https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/Screenshot-from-2021-05-29-15-14-49.png 1331w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">2 websites on web server A, 1 website on web server B, all as subdomains of a single domain name<\/h1>\n\n\n\n<p>By using multiple subdomains of the same domain name, 3 separate websites can be declared, with 2 websites hosted on web server A, and 1 website hosted on web server B, without the need to purchase additional domain names.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Bare domain and subdomain www on web server A<\/h2>\n\n\n\n<p>webpresencestepbystep.com and www.webpresencestepbystep.com on web server A<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">A note about www and CNAME<\/h3>\n\n\n\n<p>the subdomain \u201cwww\u201d host name is a canononical name (\u201cCNAME\u201d) of the @ host name, which identifies the \u201cbare\u201d domain. This means that www.webpresencestepbystep.com will resolve to the same IP address as webpresencestepbystep.com<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Virtual host profiles<\/h3>\n\n\n\n<p>\/etc\/apache2\/sites-available\/webpresencestepbystep.com.conf:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># generated 2021\/05\/18 19:42:53 EDT by addvhost.php\n&lt;VirtualHost *:80&gt;\n&lt;IfModule mpm_itk_module&gt;\nAssignUserID webpresencestepbystep_com webpresencestepbystep_com\n&lt;\/IfModule&gt;\nServerName webpresencestepbystep.com\nServerAlias www.webpresencestepbystep.com\nDocumentRoot \/usr\/web\/webpresencestepbystep_com\/webpresencestepbystep.com\nServerAdmin info@yourdomain.com\nCustomLog \/var\/log\/apache2\/webpresencestepbystep.com-access_log combined\nErrorLog \/var\/log\/apache2\/webpresencestepbystep.com-error_log\nRewriteEngine on\nRewriteCond %{SERVER_NAME} =webpresencestepbystep.com [OR]\nRewriteCond %{SERVER_NAME} =www.webpresencestepbystep.com\nRewriteRule ^ https:\/\/%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]\n&lt;\/VirtualHost&gt;<\/pre>\n\n\n\n<p>\/etc\/apache2\/sites-available\/webpresencestepbystep.com-le-ssl.conf:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;IfModule mod_ssl.c&gt;\n&lt;VirtualHost *:443&gt;\n&lt;IfModule mpm_itk_module&gt;\nAssignUserID webpresencestepbystep_com webpresencestepbystep_com &lt;\/IfModule&gt;\nServerName webpresencestepbystep.com\nServerAlias www.webpresencestepbystep.com\nDocumentRoot \/usr\/web\/webpresencestepbystep_com\/webpresencestepbystep.com ServerAdmin info@yourdomain.com CustomLog \/var\/log\/apache2\/webpresencestepbystep.com-access_log combined ErrorLog \/var\/log\/apache2\/webpresencestepbystep.com-error_log Include \/etc\/letsencrypt\/options-ssl-apache.conf SSLCertificateFile \/etc\/letsencrypt\/live\/linuxstepbystep.com\/fullchain.pem SSLCertificateKeyFile \/etc\/letsencrypt\/live\/linuxstepbystep.com\/privkey.pem\n&lt;\/VirtualHost&gt;\n&lt;\/IfModule&gt; <\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Website<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"848\" src=\"https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/Screenshot-from-2021-05-29-18-11-17-1024x848.png\" alt=\"\" class=\"wp-image-3330\" srcset=\"https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/Screenshot-from-2021-05-29-18-11-17-1024x848.png 1024w, https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/Screenshot-from-2021-05-29-18-11-17-300x248.png 300w, https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/Screenshot-from-2021-05-29-18-11-17-768x636.png 768w, https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/Screenshot-from-2021-05-29-18-11-17.png 1074w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Subdomain community on web server A<\/h2>\n\n\n\n<p>community.webpresencestepbystep.com on the same IP address, on web server A<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Virtual host profiles<\/h3>\n\n\n\n<p>\/etc\/apache2\/sites-available\/community.webpresencestepbystep.com.conf:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># generated 2021\/05\/29 12:45:14 EDT by addvhost.php<br>&lt;VirtualHost *:80&gt;<br>&lt;IfModule mpm_itk_module&gt;<br>AssignUserID community_webpresencestepbystep_ community_webpresencestepbystep_<br>&lt;\/IfModule&gt;<br>ServerName community.webpresencestepbystep.com<br>DocumentRoot \/usr\/web\/community_webpresencestepbystep_\/community.webpresencestepbystep.com<br>ServerAdmin info@yourdomain.com<br>CustomLog \/var\/log\/apache2\/community.webpresencestepbystep.com-access_log combined<br>ErrorLog \/var\/log\/apache2\/community.webpresencestepbystep.com-error_log<br>RewriteEngine on<br>RewriteCond %{SERVER_NAME} =community.webpresencestepbystep.com<br>RewriteRule ^ https:\/\/%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]<br>&lt;\/VirtualHost&gt;<\/pre>\n\n\n\n<p>\/etc\/apache2\/sites-available\/community.webpresencestepbystep.com-le-ssl.conf<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;IfModule mod_ssl.c&gt;<br>&lt;VirtualHost *:443&gt;<br>&lt;IfModule mpm_itk_module&gt;<br>AssignUserID community_webpresencestepbystep_ community_webpresencestepbystep_<br>&lt;\/IfModule&gt;<br>ServerName community.webpresencestepbystep.com<br>DocumentRoot \/usr\/web\/community_webpresencestepbystep_\/community.webpresencestepbystep.com<br>ServerAdmin info@yourdomain.com<br>CustomLog \/var\/log\/apache2\/community.webpresencestepbystep.com-access_log combined<br>ErrorLog \/var\/log\/apache2\/community.webpresencestepbystep.com-error_log<br>SSLCertificateFile \/etc\/letsencrypt\/live\/linuxstepbystep.com\/fullchain.pem<br>SSLCertificateKeyFile \/etc\/letsencrypt\/live\/linuxstepbystep.com\/privkey.pem<br>Include \/etc\/letsencrypt\/options-ssl-apache.conf<br>&lt;\/VirtualHost&gt;<br>&lt;\/IfModule&gt;<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Website<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"848\" src=\"https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/image-17-1024x848.png\" alt=\"\" class=\"wp-image-3333\" srcset=\"https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/image-17-1024x848.png 1024w, https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/image-17-300x248.png 300w, https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/image-17-768x636.png 768w, https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/image-17.png 1074w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Subdomain media on web server B<\/h2>\n\n\n\n<p>media.webpresencestepbystep.com on a different IP address, on web server B<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Virtual host profiles<\/h3>\n\n\n\n<p>\/etc\/apache2\/sites-available\/media.webpresencestepbystep.com.conf:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># generated 2021\/05\/29 17:12:33 UTC by addvhost.php<br>&lt;VirtualHost *:80&gt;<br>&lt;IfModule mpm_itk_module&gt;<br>AssignUserID media_webpresencestepbystep_com media_webpresencestepbystep_com<br>&lt;\/IfModule&gt;<br>ServerName media.webpresencestepbystep.com<br>DocumentRoot \/usr\/web\/media_webpresencestepbystep_com\/media.webpresencestepbystep.com<br>ServerAdmin info@yourdomain.com<br>CustomLog \/var\/log\/apache2\/media.webpresencestepbystep.com-access_log combined<br>ErrorLog \/var\/log\/apache2\/media.webpresencestepbystep.com-error_log<br>RewriteEngine on<br>RewriteCond %{SERVER_NAME} =media.webpresencestepbystep.com<br>RewriteRule ^ https:\/\/%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]<br>&lt;\/VirtualHost&gt;<\/pre>\n\n\n\n<p>\/etc\/apache2\/sites-available\/media.webpresencestepbystep.com-le-ssl.conf<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;IfModule mod_ssl.c&gt;<br>&lt;VirtualHost *:443&gt;<br>&lt;IfModule mpm_itk_module&gt;<br>AssignUserID media_webpresencestepbystep_com media_webpresencestepbystep_com<br>&lt;\/IfModule&gt;<br>ServerName media.webpresencestepbystep.com<br>DocumentRoot \/usr\/web\/media_webpresencestepbystep_com\/media.webpresencestepbystep.com<br>ServerAdmin info@yourdomain.com<br>CustomLog \/var\/log\/apache2\/media.webpresencestepbystep.com-access_log combined<br>ErrorLog \/var\/log\/apache2\/media.webpresencestepbystep.com-error_log<br>SSLCertificateFile \/etc\/letsencrypt\/live\/media.webpresencestepbystep.com\/fullchain.pem<br>SSLCertificateKeyFile \/etc\/letsencrypt\/live\/media.webpresencestepbystep.com\/privkey.pem<br>Include \/etc\/letsencrypt\/options-ssl-apache.conf<br>&lt;\/VirtualHost&gt;<br>&lt;\/IfModule&gt;<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Website<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"848\" src=\"https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/image-18-1024x848.png\" alt=\"\" class=\"wp-image-3335\" srcset=\"https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/image-18-1024x848.png 1024w, https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/image-18-300x248.png 300w, https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/image-18-768x636.png 768w, https:\/\/blog.gordonbuchan.com\/blog\/wp-content\/uploads\/2021\/05\/image-18.png 1074w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<p>Previous step Chapter 16: <a href=\"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/2021\/05\/19\/web-presence-step-by-step-chapter-16-using-a-script-to-automate-the-creation-of-a-virtual-host-on-an-apache-web-server\/\">Using a script to automate the creation of a virtual host on an Apache web server<\/a><br>Next step: Chapter 18: <a href=\"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/2022\/04\/24\/web-presence-step-by-step-chapter-18-installing-virtualbox-on-a-computer-running-windows-to-host-linux-as-a-virtual-machine-vm-guest\/\">Installing VirtualBox on a computer running Windows to host Linux as a virtual machine (VM) guest<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Previous step Chapter 16: Using a script to automate the creation of a virtual host on an Apache web serverNext step: Chapter 18: Installing VirtualBox on a computer running Windows to host Linux as a virtual machine (VM) guest Web presence step by step is a series of posts that show you to how to &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/2021\/05\/29\/web-presence-step-by-step-chapter-17-using-subdomains-to-host-multiple-websites-under-a-single-domain-name\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Web presence step by step Chapter 17: Using subdomains to host multiple websites under a single domain name&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-3299","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=3299"}],"version-history":[{"count":65,"href":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3299\/revisions"}],"predecessor-version":[{"id":3700,"href":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3299\/revisions\/3700"}],"wp:attachment":[{"href":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=3299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=3299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.gordonbuchan.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=3299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}