2

I want to set up a subdomain using virtual hosts. I have altered the httpd.conf file as follows, but I get a "can't find server" error when I try to access the url. I'm running Centos 5.5.

NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#<VirtualHost *:80>
#    ServerAdmin [email protected]
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>

<VirtualHost *:80>
ServerName www.mydomain.com
DocumentRoot /var/www/html/
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/var/www/vhosts/test_mydomain_com/"
    ServerName test.mydomain.com
    ErrorLog logs/test_mydomain_com-error_log
    CustomLog logs/test_mydomain_com-access_log common
</VirtualHost>

I have:

  • Checked the syntax is valid by "service httpd configtest"
  • Restarted Apache
  • Checked that the DocumentRoot described above does indeed get to the folder I have my index.php file in for the subdomain.

I'm suprised that even though it can't find the subdomain, it doesn't get routed to the www.mydomain.com area because that's what I thought that I'd set it up to do with the first virtual host statement.

I'm trying to access the subdomain by:

http://test.mydomain.com

Do I need to do anything to (and thus learn about) the DNS settings to acheive what I want here? Is that what could be going wrong?

2 Answers 2

3

You need either a A record or CNAME record added to your DNS server in order for that to work. Sounds like you do not have one. You can confirm for us by posting host test.mydomain.com.

If you get back:

Host test.mydomain.com not found: 3(NXDOMAIN)

Then that is your problem.

Either add an A record (hostname -> IP) or a CNAME (hostname -> hostname) for test.mydomain.com and you should be in business.

3
  • Which file do I need to alter to add the A record? I've gone through a chapter on DNS in a book I have on Centos which used bind-chroot but it's got very complicated and I'm not sure I need it all. It has suggested setting up my own DNS server. Do I need to do this? Is there not just a one line A record that I can add somewhere.
    – Joe
    Jul 15, 2011 at 17:45
  • 3
    I do not recommend setting up your own DNS server, it far more complicated than is necessary. Presumably someone already hosts your DNS for "mydomain.com"; whoever/whereever that is hosted is where you'll simply want to add (or have them add) a new A or CNAME record. Usually this is as simple as adding one line to the DNS zone file, updating the SOA and reloading the named process. Jul 15, 2011 at 17:59
  • Great. Yes I did this and it's working now. Many thanks for coming back to me on this. I don't know why I didn't think of doing that. I must play around with this though as I want to understand it all. Main thing is that I can now add domains and subdomains which is great! Thanks for your help.
    – Joe
    Jul 15, 2011 at 18:06
2

If you're getting a "Server not found" error, then that's likely a DNS problem, not apache.

Did you create a DNS record for the new subdomain?

1
  • No I didn't. I'll have a go. Thanks for the reply.
    – Joe
    Jul 15, 2011 at 14:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .