how to create a subdomain in a dedicated apache2 server

0

Issue

I want to create a subdomain I followed this steps :

cd /etc/apache2/sites-available
nano test.mydomaine.com

<VirtualHost *:80>
        ServerAdmin mymail@gmail.com
        ServerName  test.mydomaine.com
        ServerAlias www.test.mydomaine.com
        DocumentRoot /var/www/testfolder/
<Directory "/var/www/testfolder">
        AuthType Basic
        AuthName "test"
        AuthUserFile /var/www/testfolder/passwords
        Require valid-user test
</Directory>
</VirtualHost>

exit and save

a2ensite test.mydomaine.com
/etc/init.d/apache2 reload

but It’s not working am I missing something ?

Solution

In order for this to work, you additionally have to configure DNS resolution for the new hostname test.mydomain.com. If you are just playing with this locally and do not want to create a “real” DNS entry, you have to edit the file /etc/hosts so that your computer can resolve the hostname to an IP address. If you are running the web server on the same machine as the browser, you will want to map test.mydomain.com to 127.0.0.1. If the browser is on a different machine on your local network, you’ll need to determine the server’s IP address and then on the browser machine, edit /etc/hosts to add the mapping.

On Windows, the file is called C:\windows\system32\drivers\etc\hosts

A sample entry would be (for the browser running on the same machine as the server):

127.0.0.1 test.mydomain.com

If the server is at, say 192.168.0.5, the entry would be

192.168.0.5 test.mydomain.com

EDIT: If the server has a real routable IP address, then if you want the test.mydomain.com address to resolve on the global Internet you will have to get your service provider to add it to DNS. For testing purposes, you can still use /etc/hosts as described above. Just substitute the server’s real IP instead of 127.0.0.1. Do this on the system where you are running the browser.

Answered By – Jim Garrison

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More