Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Main Support Categories > Server Platforms
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Server Platforms
Discussion regarding the Ubuntu Server Edition. For more information on the Ubuntu Server Team, please visit their wiki page or Launchpad page.

 
Thread Tools Display Modes
Old October 6th, 2009   #1
BassKozz
Dipped in Ubuntu
 
BassKozz's Avatar
 
Join Date: Jun 2007
Beans: 600
Ubuntu 9.10 Karmic Koala
Apache Multiple VirtualHosts on the same IP (VM)

I am running 64bit Ubuntu 9.04 Server, in Virtual Box. I have installed the LAMP stack, and I am having a hard time getting VirtualHosts to work. I have given the VM it's own static IP address (192.168.1.105) and I have given it the hostname "LAMPVM" via my router, and when I try to access it from my browser it only goes to 1 domain at a time.

I have "vhost_alias" & "rewrite" enabled.

I have my /etc/apache2/httpd.conf setup as follows:
Code:
<Directory "/home/USER/workspace">
        Options FollowSymLinks
        AllowOverride All

        Order allow,deny
        Allow from all
</Directory>

NameVirtualHost *
ServerName localhost
I have the following sites-enabled:
localhost:
Code:
<VirtualHost *>
        ServerName localhost
        ServerAlias localhost *.localhost
        VirtualDocumentRoot /home/USER/workspace/%1/
</VirtualHost>
test1:
Code:
<VirtualHost *>
        ServerName test1
        ServerAlias test1 *.test1
        DocumentRoot /home/USER/workspace/test1/
</VirtualHost>
test2:
Code:
<VirtualHost *>
        ServerName test2
        ServerAlias test2 *.test2
        DocumentRoot /home/USER/workspace/test2/
</VirtualHost>
And I enter "LAMPVM" into my browser it only goes to the most recent domain I added (test2).
If I enter "test1.LAMPVM" into my browser it doesn't find the address.
I realize this is because my DNS on my browsers machine (not the VM) is not configured to recognize what "test1.LAMPVM" means. But when I enter the following into my /etc/hosts file:
Code:
127.0.0.1       localhost
127.0.1.1       my-machine

#LAMPVM
192.168.1.105 test1.lampvm
192.168.1.105 test2.lampvm
By browser goes to the address "test2.lampvm", but it thinks "test1.lampvm" is the same as "test2.lampvm" (or "test1.lampvm" is being routed to the most recently added domain [which happens to be test2]).
Again, I kinda get why this isn't working because both "test1.lampvm" and "test2.lampvm" are pointing to the same address (192.168.1.105), but that is the address of the VM, and I don't know how else to get access to multiple domains on the same VM/IP?

My guess is I probably need to make some adjustments in my Router, but not sure exactly what?
Any/All Help, Comments, Suggestions will be greatly appreciated.
-BassKozz
__________________
Ubuntu 9.10 64-bit - IP35-Pro | Q6600@3.3ghz(TRUE [lapped]) | G.Skill 2x2GB | MSI NX8600GT | 150GB WD Raptor ||| NAS - Ubuntu 9.04 - Intel D865GBF | P4 3.0GHz | G.Skill 4x1GB | FX5200-AGP | 3x250GB mdadm Raid5 | 200GB OS

Last edited by BassKozz; October 6th, 2009 at 10:54 AM..
BassKozz is offline   Reply With Quote
Old October 6th, 2009   #2
cdenley
Tall Cafè Ubuntu
 
Join Date: Dec 2006
Location: Chicago
Beans: 2,536
Re: Apache Multiple VirtualHosts on the same IP (VM)

First of all, you shouldn't be using httpd.conf. You should create vhost configurations in /etc/apache2/sites-available, then enable them with a2ensite. The default vhost should be /etc/apache2/sites-available/default. If your server is ubuntu 9.04, NameVirtualHost should only be used in /etc/apache2/ports.conf.

You seem to have the server names configured as test1, test2, etc., so why are you configuring your hosts file with test1.lampvm, test2.lampvm, etc.?

If you don't want to edit /etc/hosts or worry about browser caching or routing, you could use netcat to have full control over the http headers.
Code:
echo -e "GET / HTTP/1.0\nHost: test1\n"|nc localhost 80
Of course, make sure you reload apache after changing any vhost configuration.

Get apache working properly, then figure out routing.

Last edited by cdenley; October 6th, 2009 at 11:24 AM..
cdenley is offline   Reply With Quote

Bookmarks

Tags
apache, lamp, networking, virtualhosts, virtualmachine

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:58 AM.


vBulletin ©2000 - 2010, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. lingonberry