0

My site has one IP. They set for me tww records into DNS servers: www.mydomain.com --> admin.mydomain.com -->

My apache httpd.conf reads as follows:

...
ServerName www.mydomain.com:80
DocumentRoot "/home/somewhere/www"

NameVirtualHost <IP A>:80

<VirtualHost <IP A> >
    ServerAdmin webmaster@mydomain
    DocumentRoot /home/somewhere/www/admin
    ServerName admin.mydomain.com

</VirtualHost>

Now, if I type www.mydomain.com or admin.mydomain.com I get the same page, i.e. the main server. The nslookup command shows that both www.mydomain.com and admin.mydomain.com point to IP A. Any help?

gdm
  • 459
  • 2
  • 5
  • 19
  • 2
    It looks like English is not your first language, so let me help you say that better: My site has one IP with two DNS A records (www.mydomain.com and admin.mydomain.com) pointing at the same IP address. My apache httpd.conf is as follows: (You might want to change the question to be more specific: "How do I debug Apache VirtualHosts when they don't work?" – TomOnTime Jun 17 '14 at 13:06

2 Answers2

1

You could try something like this with two different VHost:

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "/usr/local/docs/www"
    ServerName www.mydomain.com
    ServerAlias mydomain.com
    ErrorLog "/var/log/www-error_log"
    CustomLog "/var/log/www-access_log" common
</VirtualHost>
<VirtualHost *:80>
        DocumentRoot "/usr/local/docs/admin"
        ServerName admin.mydomain.com
        ErrorLog "/var/log/admin-error_log"
        CustomLog "/var/log/admin-access_log" common
</VirtualHost>
Thomas L.
  • 181
  • 1
  • 1
  • 5
  • Why it works? Shall we always omit the IP address ? – gdm Jun 17 '14 at 13:16
  • There is three ways to manage VHost, by IP, by Name or by port. If you want to manage it with names, then you put *:80 so you accept any IP on port 80. – Thomas L. Jun 17 '14 at 13:17
1

What is the output of "apachectl -S"? When I need to debug VirtualHosts this is the first command I use. It tell me what the configuration looks like to Apache.

I generally use one VirtualHost for each host, and let the main site (non-virtual) go to a page that says, "If you see this, something is wrong."

<VirtualHost *:80>
        ServerName mydomain.com
        ServerAlias www.mydomain.com
        ...
        ...
</VirtualHost>

<VirtualHost *:80>
        ServerName admin.mydomain.com
        ...
        ...
</VirtualHost>
TomOnTime
  • 7,945
  • 6
  • 32
  • 52
  • I did your command: no problem is shown – gdm Jun 17 '14 at 13:19
  • Apache searches the list in order. If you pretend to be Apache, what would a request for "admin.mydomain.com" match? What would "www.mydomain.com" match? – TomOnTime Jun 17 '14 at 13:20