Knowledgebase

Portal Home > Knowledgebase > Articles Database > Help me understand virtual hosting...


Help me understand virtual hosting...




Posted by Carlo Gambino, 06-01-2009, 04:56 PM
Hello again! I have recently decided to experiment with virtual hosts on my local server, and come to find the following issue: I have 2 virtual hosts set up now, www.mysite1.com and www.mysite2.com. In order to accomplish this, I first created new users on the system named mysite1 and mysite2 (for simplicity). Each user has a /home/user/htdocs directory which is where the page files should live. Then I edited /etc/apache2/conf.d/virtual.conf and added the line Code: NameVirtualHost * Then I created a virtual site for each host: /etc/apache2/sites-available/mysite1.com /etc/apache2/sites-available/mysite2.com and finally enabling the sites: Code: sudo a2ensite mysite1.com sudo a2ensite mysite2.com After restarting apache, I was expecting my virtual hosts to be enabled so I threw a different index.html page in each htdocs file... now when I call www.mysite1.com in my browser it works fine, but when I call www.mysite2.com, it shows the html for mysite1! Even more strange, is that when I call www.mysite2.com/info.php it displays that of mysite1 even though there is no info.php in the /home/mysite2/! Please help me understand what I'm missing!

Posted by eth00, 06-01-2009, 05:47 PM
Did you add an actual virtualhost section for both? The first works because it is the first docroot listed and will get picked up. It sounds like site2's vhost is probably setup wrong.

Posted by Karl, 06-01-2009, 06:58 PM
This is the same problem I had. This is how I fixed it:

Posted by mwatkins, 06-01-2009, 07:35 PM
eth00 has probably nailed it; or perhaps the default docroot is being picked up. Sounds familar, to readers of other threads on this topic of late. Rather than complicate matters with a non-standard script (a2ensite and such) which doesn't ship with Apache itself, why not first simplify things until you fully understand Apache virtual hosting... just edit httpd.conf and add two simple VirtualHost declarations, save the file, run apachectl configtest to check for obvious errors, and restart Apache. Test. Didn't work? Check your error log(s). Fix and restart. Post 6 of this very recent thread contains a link to the Apache vhost documentation and a trouble shooting reminder. Once you've got basic VirtualHost definitions working in httpd.conf, then play with scripts like a2ensite if you still feel the need.

Posted by Carlo Gambino, 06-02-2009, 09:44 AM
Thanks very much for the input and advice. I will be experimenting more with what you've given me and I'll report back soon.

Posted by ferdy, 06-03-2009, 06:23 AM
Great help.thanks

Posted by Carlo Gambino, 06-03-2009, 05:23 PM
Thanks for the thought provoking insight! It's nice to have people who know what they're talking about to guide me through this adventure! I hadn't originally but have since, I was really hoping this would solve my problem but no dice! I wasn't thoroughly understanding /etc/apache2/conf.d/virtual.conf, but I did make the suggested changes to look like your suggestion. However, upon reloading apache2, I get the following errors (I made the changes it was mad about so just grouped all errors in one here): Now... I have not changed anything in apache2.conf except adding this line: And this is my virtual.conf as it's written now: I am a firm believer in Akem's Razor. The simplest solution is usually the best, hands down! I would love to learn a "simpler" way of accomplishing what I want here, but I have had trouble figuring that out. For example, you suggest I use httpd.conf to manage this task, but my httpd.conf file is blank. From what I understand, apache2 relies on apache2.conf and not httpd.conf- is this incorrect? I have been researching this option and it would seem that this could be accomplished within the apache2.conf but I don't see it being any easier than the original route I've taken. Any further input or education would be helpful.



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
Mochahost (Views: 581)
GeoIP with HAproxy? (Views: 571)


Language:

Contact us