Link to home
Start Free TrialLog in
Avatar of fletchsod
fletchsod

asked on

Name Virtual Host and/or Virtual Host not working...

I have been going around in a circle for a few days.  Basically, the problem here is that the 2nd website kept defaulting to the 1st website.  I'm using the IP Address based virtual host because I'm behind the firewall and because it's faster when there's problem with the Internet (like DNS, down Internet connection, etc...).  The 2nd website is accessible only behind the firewall, not accessible to the public.  The 1st website is accessible to the public and behind the firewall.  I'm going to post the script here...  I'm using hte Unix server and the machine name is chevy.  I'm also wondering if creating a fake ip address is ever possible...

#/etc/hosts (Script below)
--snip--
127.0.0.1               loopback localhost      # loopback (lo0) name/address

#IP Address for this Machine...
xx.xx.x.90    chevy chevy.xxxx.com

#IP Address for Websites
xx.xx.xx.90    firstwebsite.xxxx.com
xx.xx.xx.91    secondwebsite.xxxx.com
--snip--

#httpd.conf (Script below - trimmed)
--snip--
#Listen xx.xx.xx.90:80
#Listen xx.xx.xx.90:443
#Listen xx.xx.xx.91:80
#Listen xx.xx.xx.91:443

NameVirtualHost xx.xx.xx.90:80
NameVirtualHost xx.xx.xx.90:443
NameVirtualHost xx.xx.xx.91:80
NameVirtualHost xx.xx.xx.91:443

<VirtualHost xx.xx.xx.90:80>
    ServerName firstwebsite.xxxx.com
    DocumentRoot "/home/website/firstwebsite/www"
    DirectoryIndex index.php
</VirtualHost>

<VirtualHost xx.xx.xx.90:443>
    ServerName firstwebsite.xxxx.com
   DocumentRoot "/home/website/firstwebsite/secure"
   DirectoryIndex login_page.php
</VirtualHost>

<VirtualHost xx.xx.xx.91:80>
    ServerName secondwebsite.xxxx.com
    DocumentRoot "/home/website/secondwebsite/www"
    DirectoryIndex index.php
</VirtualHost>

<VirtualHost xx.xx.xx.91:443>
    ServerName secondwebsite.xxxx.com
   DocumentRoot "/home/website/secondwebsite/secure"
   DirectoryIndex login_page.php
</VirtualHost>
--snip--

#Response as result of command line "httpd -S"
--snip--
VirtualHost configuration:
xx.xx.xx.90:80        is a NameVirtualHost
                            default server firstwebsite.xxxx.com (/xx/httpd.conf:1264)
                            port 80 namevhost firstwebsite.xxxx.com (/xx/httpd.conf:1264)
xx.xx.xx.90:443      is a NameVirtualHost
                            default server firstwebsite.xxxx.com (/xx/httpd.conf:1299)
                            port 443 namevhost firstwebsite.xxxx.com (/xx/httpd.conf:1299)
xx.xx.xx.91:80        is a NameVirtualHost
                            default server secondwebsite.xxxx.com (/xx/httpd.conf:1351)
                            port 80 namevhost secondwebsite.xxxx.com (/xx/httpd.conf:1351)
xx.xx.xx.91:443      is a NameVirtualHost
                            default server secondwebsite.xxxx.com (/xx/httpd.conf:1386)
                            port 443 namevhost secondwebsite.xxxx.com (/xx/httpd.conf:1386)
--snip--

Thanks,
 Scott Fletcher
Avatar of ahoffmann
ahoffmann
Flag of Germany image

how do you access the server? could you pleast post the exact URL
how does the xx.xx.xx.91 resolve to, is it secondwebsite.xxx.com or firstwebsite.xxx.com

try to do nslookup 91.xx.xx.xx.in-addr.arpa   (replace the xx's with the real ip addre in reverse, so if your real ip is 1.2.3.91, then nslookup 91.3.2.1.in-addr.arpa).

Alternately, you could try to add modify:
<VirtualHost xx.xx.xx.91:80>
    ServerName secondwebsite.xxxx.com
    ServerAlias xx.xx.xxx.91                             <<-- add this line.
    DocumentRoot "/home/website/secondwebsite/www"
    DirectoryIndex index.php
</VirtualHost

--
give it a shot.
Avatar of fletchsod
fletchsod

ASKER

>> how do you access the server? could you pleast post the exact URL?
Well, the website is not accessible on the Internet just yet.  But all is not lost, there is one other website that use this exact configuration which doesn't work either.  It is www.e-cbi.com, the problem is you only see the public ip address which is 64.31.133.14.  When it reach the firewall, a different ip address is used behind the firewall, known as private ip address.  That's where the xx.xx.xx.90 come into play.  The second website is test.e-cbi.com and it does not exist on the Internet, just us employees on local network who can access it.

>> how does the xx.xx.xx.91 resolve to, is it secondwebsite.xxx.com or firstwebsite.xxx.com
The xx.xx.xx.91 resolve to the secondwebsite.xxx.com.

>>try to do nslookup 91.xx.xx.xx.in-addr.arpa
Tried that and got a error message, see below
--snip--
*** Can't find server name for address 64.31.129.6:No response from server
*** Can't find server name for address 64.66.88.6:No response from server
*** Default servers are not available
--snip--
The server is configured to depend on itself and on the host file.  The DNS is disabled here because of the firewall.

>>    ServerAlias xx.xx.xxx.91                             <<-- add this line.
 Tried that and it still doesn't work.  Apache kept picking the firstwebsite.xxx.com...

Scott Fletcher
i would assume that you have gone thru Apache docs on Vhost ont he following link?

http://httpd.apache.org/docs-2.0/vhosts/
http://httpd.apache.org/docs-2.0/vhosts/details.html
I use Apache 1.3.27, not the 2.0 version.  So, I did see and look through the documentation at
http://httpd.apache.org/docs/vhosts/ip-based.html and  http://httpd.apache.org/docs/vhosts/name-based.html and stuffs like that.  So, anyway, I saw some new information from the links you provided for the docs-2.0 directory that wasn't in the docs directory..

1) ServerAlias and ServerPath checks are never performed for an IP-based vhost
2) # If two IP-based vhosts have an address in common, the vhost appearing first in the config file is always matched. Such a thing might happen inadvertently. The server will give a warning in the error logfile when it detects this.
3) You should never specify DNS names in VirtualHost directives because it will force your server to rely on DNS to boot
4) ServerName should always be set for each vhost. Otherwise A DNS lookup is required for each vhost

While what I read from the docs directory

1)  It is recommended that you use an IP address instead of a hostname
2) If your server doesn't have to perform DNS for any other reason then you might be able to get away with running Apache with the HOSTRESORDER environment variable set to "local". This all depends on what OS and resolver libraries you are using.
3) Tips to Avoid these problems

    * use IP addresses in <VirtualHost>
    * use IP addresses in Listen
    * use IP addresses in BindAddress
    * ensure all virtual hosts have an explicit ServerName
    * create a <VirtualHost _default_:*> server that has no pages to serve

Aw, forget it.  I can't wait any longer.  I just made the secondwebsite.xxxx.com to use the same IP Address as the firstwebsite.xxxx.com, the same IP Address as the webserver's IP Address and that took care of the problem.  I don't know why it won't work with other IP Addresses...  So, closing this report....   (Will contact the community something...)
no objection.
>>fletchsod: If you have not responded to the Experts concerning your question or given an updated status, your
>>points will not be refunded.
Me??  I already provided the answer from just one posting before your comments..  The answer was that I start using the the same IP Address for 2 websites because there's no way to get the 2nd IP Address to work.  So far, so good.

Scott Fletcher
ASKER CERTIFIED SOLUTION
Avatar of Netminder
Netminder

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial