What you have in hand:
You have a computer with a domain name pointing your machine's public IP.What you want to do:
Create a subdomain for your server. For example, you have example.com and you want to have www.example.com.What you essentially needs to do:
Create a virtualhost on your Apache server. In other words, although both www.example.com and example.com all pointing to the same IP address, you can process them differently.How you can do it, ideally:
1. Go to /etc/apache2/sites-available/
2. Copy 000-default.conf to 001-example.conf. Name does not matter.
3. Add basic template to the new .conf file.
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/www.example.com
</VirtualHost>
4. Create a corresponding folder in /var/www, which is "www.example.com". Again the name does not matter.
Why you won't succeed:
The Internet do NOT have the DNS record for the www.example.com. In other words, when you type in www.example.com in your browser, you browser cannot find the corresponding IP address for this URL, which means the traffic will never arrive to your machine.
How you deal with it:
Go ask your DNS provider (or parent domain) admin to delegate DNS records to your machine, meaning that your machine will need to act as both the web-server and DNS server. Whenever a strange URL comes, such as wtf.example.com, your parent DNS server knows that you might know the IP and you're the delegated server for your zone, so it will forward the request to you now. Now it's up to your server to decide which IP the wtf.example.com belongs to.
Then, how do you setup DNS Server then?
1. a "zone" at /etc/bind/named.conf.local. Something like this:
zone "example.com" {
type master;
file "zones/unsigned/example";
};
2. create a folder /var/cache/bind/zones/unsigned/. Create a file named "exmaple.com". Name MATTERS now.
3. Edit the file and add the following content :
$TTL 60
$ORIGIN exmaple.com.
@ 1D IN SOA ns1example.com. root.example.com. (
2014100200 ; serial
360 ; refresh (6 minutes)
360 ; retry (6 minutes)
1800 ; expire (30 minutes)
60 ; minimum (1 minute)
)
IN NS ns1.example.com.
ns1 IN A YOURIP
www IN A YOURIP
Note, remember to replace YOURIP with your actual IP address.
4. sudo service bind9 restart
5. sudo service apache2 restart
No comments:
Post a Comment