Jump to content

  •  

Photo

Creating subdomains in Apache


  • Please log in to reply
No replies to this topic

#1 brent

brent

    Administrator

  • Administrators
  • 11 posts

Posted 17 February 2013 - 04:50 PM

sub-domains is a good way to organize your website.  example.com is what we will call the parent domain. You could have many different parts to  your website. For example you could have forums, books, music, really anything. so instead of having all your components to your website lay in the same directory /var/www  you could go a step further and organize it. Here is an example of how you could structure /var/www using sub-domains

 

/var/www/example.com   { Main domain }

/var/www/forums              { forums }

/var/www/music                {if you have a music site or streaming}

/var/www/books                { digital books site}

 

 

 

By using this type of structure to set up sub-domains all your website components eg: forums, music, books wont have to all be in the root directory of the website. Do you like www.example.com/forums? or would you rather see forums.example.com? 

 

Here is how we accomplish this.

 

 We need to navigate to

cd /etc/apache2/sites-available/
 

 

 

Now we are going to create our sub-domain file.

sudo nano forums.example.com
 

 

 

 

We will use a virtual host here is what it will look like.

<VirtualHost *:80>
ServerName forums.example.com
ServerAlias www.forums.example.com
DocumentRoot /var/www/forums/
</VirtualHost>
<Directory /var/www/forums/>
                Options -Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
</Directory>
 

 

 

 

Next we will need to enable the site with apache2.

sudo a2ensite forums.example.com
 

 


Now we need to reload apache for the changes to take place.

sudo /etc/init.d/apache2 reload
 

 

Now all you need to do is create a folder in /var/www called forums eg; /var/www/forums

 

In order for you to be able to access the forums.example.com you will need to modify DNS and add an A record. You Can go to the registar where you got the domain and register the sub-domain and point it to your server, you could use a third party dns such as zoneedit to handle all your dns needs for your domain 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users