Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Virtual Hosts 1

Status
Not open for further replies.

cmccreery

Programmer
Oct 12, 2005
14
CA
Newbie here, I have configured multiple virtual hosts on my server. Each points to the proper directories. However I have a problem when trying to bring up one site and then another. Say I open site1.com it displays properly, then I browse to site2.com it loads the layouts of my site1.com site but with some broken links and image files.

<VirtualHost *:80>
ServerName site2.com
DocumentRoot "C:\Program Files\Apache Group\Apache2\htdocs\site2"
</VirtualHost>

<VirtualHost *:80>
ServerName site1.com
DocumentRoot "C:\Program Files\Apache Group\Apache2\htdocs\site1"
</VirtualHost>

This is what I have in my conf file. Any ideas? Thanks in advance.
 
Yup got that above the virtual hosts.

NameVirtualHost *:80

Each time I restart the Apache2 service and refresh the page it loads the proper virtualhost (site1.com) but then if I try to access site2.com it just reloads what looks like a broken site1.com
 
Hi

I tried exactly what you done, I mean giving the port number too, and this is Apache's reaction :
[Thu Oct 13 16:01:19 2005] [error] VirtualHost *:80 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results

And now my virtual hosts are messed too, kind of how you described it. So try without the port number :
Code:
<VirtualHost *>
[gray]# whatever was before[/gray]
</VirtualHost>

Feherke.
 
Ok So I removed the port number but to no avail. If I load site1.com, looks great, load site2.com not so good. If I refresh the page multiple times quickly it loads the site but then if I start to navigate thru site2.com it goes back to site1.com but with broken images and missing css grrrrrrrrrrrrrrrrrrrr
 
Another thing I noticed is that if I call up the sites using the default domain followed by the directory they work fine, for example site.com/site1 or site.com/site2 these all load perfectly.
 
Hi

httpd.conf said:
# The first VirtualHost section is used for requests without a known server name.
In some cases putting an empty [tt]VirtualHost[/tt] section before the first real virtual host settings, may help.
Code:
<VirtualHost *>
</VirtualHost>

Feherke.
 
Hi

Yes, I have Apache/2.0.54. Is on Linux, but in this case, as I know, this does not matter.

Maybe the configuration file's name is different. So configure it where you used to.

Feherke.
 
Hmmm well I am stuck. I was running Apache 1.3 and it worked fine then but since I've upgraded to 2.054 no dice. Could it be an issue with my Coldfusion server?
 
Hi

No more proper idea, at this point I would try to analyze the HTTP headers, mostly request but response too.

What browser/version use ? When you access site2 after site1, how you pass forward to it ? Following a link, redirection or just type in the URL in address bar ?

Feherke.
 
Sorry if this was already done but try saying
NameVirtualHost * and in your VirtualHost containers just state <VirtualHost *> no port numbers. Also, does it only mess up if you access site2 after site1?

Also, where did you specify the name to IP address mapping for site1.com and site2.com and what are their entries?
 
Hey thanks for the tip, I've tried that and it doesn't matter which site. If I load site1 first after restarting then site2 won't display and vice versa.

No sure what you mean about name to IP address mapping DNS?
 
You're trying to do name based virtual hosting. When you type site1.com into the web browser, your computer needs to resolve that name to the IP address of the web server. When the web server receives the request from the client, it will see the name of the site which it should server. Therefore, the names site1.com and site2.com have to be able to resolve to an IP address of the web server. For example, you can place the following inside your /etc/hosts file on your client to do local name resolution.

site1.com 192.168.1.1
site2.com 192.168.1.1

Here both sites are mapped to the same IP address assuming your web server is at 192.168.1.1. Also, you might want to try specifying a specific IP address for NameVirtualHost and then change your VirtualHost containers to use the IP address just to see if the problem still occurs.
 
How to set up Name Based Vitualhosts on Apache. faq65-1831
 
The problem looks to be broken links in your page for the second one. If I clear my cache and go to the second page, no pictures show up. But the first page always has the pics. Are you sure you have an images directory under the DocumentRoot for both virtual hosts?
 
That's the biggest problem is that the sites are completely different. They should resemble each other at all.
 
Are you trying to say that site2 is reading site1's index.html file? If so, did you check that site2's index file is correct?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top