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?

Roman
  • 3,907
  • 3
  • 21
  • 34
nmagerko
  • 189
  • 1
  • 1
  • 7

3 Answers3

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?).

fideloper
  • 353
  • 3
  • 11
  • 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 06 '13 at 03:05
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 06 '13 at 03: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` ? –  Jul 06 '13 at 03: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 06 '13 at 03: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. –  Jul 06 '13 at 03:35
  • From Apache's access.log, I get `Apache/2.2.22 (Ubuntu) (internal dumy connection) and from error.log, I get an error about an absent WSGI script or one that is unable to start. So I'm thinking that this is a problem with my WSGI (these subdomains point to Django projects). I'll try to fix it really quickly – nmagerko Jul 06 '13 at 03:40
  • 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. –  Jul 06 '13 at 03:45
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.

Daniel Widrick
  • 3,488
  • 2
  • 13
  • 27