Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a dedicated linux machine on the internet and I want to be able to access subdomains directly like:

http://abcd.example.com

I've setup httpd.conf as follows:

NameVirtualHost *:80

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

<VirtualHost *:80>
  ServerName david.example.com
  DocumentRoot /home/david/public_html
</VirtualHost>

<VirtualHost *:80>
  ServerName matthew.example.com
  DocumentRoot /home/matthew/public_html
</VirtualHost>

But the subdomains are not accessible. What changes, if any do I need to make in /etc/hosts? I tried:

127.0.0.1 localhost.localdomain localhost
# Auto-generated hostname. Please do not remove this comment.
99.99.99.99 vps.example.com vps david.example.com matthew.example.com

and

127.0.0.1 localhost.localdomain localhost
# Auto-generated hostname. Please do not remove this comment.
99.99.99.99 vps.example.com vps
99.99.99.99 david.example.com david
99.99.99.99 matthew.example.com matthew

But neither worked.


Q1: Do I need to change any DNS setting(s)?

Q2: Do I need to set some special permissions on /home or /home/[user]?

share|improve this question

2 Answers 2

I am assuming that by "But the subdomains are not accessible" you mean they are not accessible remotely. If that is the case, then adding them to /etc/hosts will not help, as /etc/hosts only overrides local hostname lookups. If you want the subdomains to be accessible from the internet, you need to add them to the DNS for your domain name. Your hosting provider should be able to help you with that.

share|improve this answer
    
Thanks for the @insyte! I think I missed that in my understanding... :( –  siliconpi Jan 25 '11 at 5:10
    
actually, godaddy (where the domain has been registered) says: "DNS Manager: (Not hosted here)" –  siliconpi Jan 25 '11 at 5:32
    
and the hosting provider has provided a VPS within which this site is hosted. –  siliconpi Jan 25 '11 at 5:32
    
So where is the DNS managed? You can find out by looking at the domain servers listed in the WHOIS record or in the output of "dig ns example.com" –  Insyte Jan 25 '11 at 6:11
    
Also it would be helpful if you describe what you mean by "not accessible." What error shows up in a browser when you attempt to access the domains? –  Insyte Jan 25 '11 at 6:12

Check with your hosting provider or if you have access to your domain panel create desired subdomain and map the IP address of your machine in A Record for all those virtaulhosts so that the subdomain will point to your server and apache via your virtualhost configuration will through the desired pages.

good luck!!

:D

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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