1

I would like to make two subdomains for my site. To do so, I have created three VirtualHosts in my default file under sites-available (I am using Apache on Ubuntu):

<VirtualHost 127.0.0.1>
     ServerName nmagerko.me
     ...
     DocumentRoot /var/www
     ...
</VirtualHost>

<VirtualHost 127.0.0.1>
     ServerName sub1.nmagerko.me
     ...
     DocumentRoot /some/different/path
     ...
</VirtualHost>

<VirtualHost 127.0.0.1>
     ServerName sub2.nmagerko.me
     ...
     DocumentRoot /some/different/path2
     ...
</VirtualHost>

However, I am not sure of what to do after this point. I have each of these subdomains and my primary domain in my /etc/hosts file as 127.0.0.1 and I have set A Records for sub1 and sub2 in my domain registrar's domain editor. However, these A Records point to the same IP as my primary domain, since this is all being hosted on one system... which isn't very useful. So, when I go to sub1.nmagerko.me in my browser, I receive the same site as I would have as if I went to nmagerko.me.

Any suggestions on how to proceed?

closed as off-topic by Jenny D, Nathan C, Ward, Scott Pack, Sven Jul 7 '13 at 20:40

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about hardware or software used in a home setting are off-topic because they require answers that may not be practical for the business and support professionals here. You should try asking on Super User instead." – Jenny D, Nathan C, Ward, Scott Pack, Sven
If this question can be reworded to fit the rules in the help center, please edit the question.

2

Hmm, the config you wrote seem correct to me, so I will try to show you how to debug the problem:

1- Make sure that DNS is correctly configured executing dig nmagerko.me, dig sub1.nmagerko.me and dig sub2.nmagerko.me and looking for the IP. Use wget X.nmagerko.me to tests, browser could be caching DNS replies.

2- Make sure that files in /some/different/path, /var/www and /some/different/pat2 are different.

3- Make sure you restart apache with

sudo service apache2 restart

Beside, you can take a look at logs too.

Hope this help.

  • Well, when I executed wget sub1.nmagerko.me I got a 404, even though the DNS appeared to be configured correctly. – nmagerko Jul 6 '13 at 3:10
  • What about wget nmagerko.me? You said in the question "when I go to sub1.nmagerko.me in my browser, I receive the same site as I would have as if I went to nmagerko.me." Do you have an index.html or an index.php file in the path pointed by sub1.nmagerko.me DocumentRoot? I mean, exist /some/different/path/index.html ? – gsi-frank Jul 6 '13 at 3:15
  • Yes so nmagerko.me is currently a 404 (on purpose). However, sub1 and sub2 (these are just example subdomains) also give the 404 of the primary site. Instead, they should provide a different page for each. – nmagerko Jul 6 '13 at 3:30
  • Could you put here what apache log said when you make a requests? Execute tail -f /var/log/apache2/access.log and tail -f /var/log/apache2/error.log and then the three wget commands and you will see in logs where apache is looking for the files, if in the same directory or not. – gsi-frank Jul 6 '13 at 3:35
  • 1
    I recommend you try to debug the VirtualHost config with simple sites configurations, then, when you are sure that Apache config is working, add whatever you want. – gsi-frank Jul 6 '13 at 3:45
3

Try changing the IP address to just port 80 in all instances:

<VirtualHost *:80>
    ServerName nmagerko.me
    ...
    DocumentRoot /var/www
    ...
</VirtualHost>

This may help to solve an issue where the virtual host is listening for internal (local) traffic only. Since you're setting your domains A records, I'm assuming you're using a publicly available server?

Don't forget to reload apache after any conf file change:

$ sudo service apache2 reload

Lastly, let us know of this is just you testing locally. If it is, you likely don't need to change your domain's A record (unless you're hosting your own private DNS?).

  • Well I am using a server that I have at my residence. So it's just a single, private server. The problem is that I am setting an A record, but it is sending back the information for nmagerko.me instead of sub1.nmagerko.me – nmagerko Jul 6 '13 at 3:05
1

Without the entire httpd.conf (including includes) it's impossible to tell from here, but adding

NameVirtualHost 127.0.0.1:80

above your first <virtualHost domain:80> may help? Restart apache after the change.

Not the answer you're looking for? Browse other questions tagged or ask your own question.