Name Based Virtual Hosting in Apache with a Linksys Router

smr

Junior Member
Jun 1, 2001
12
0
0
Anyone have any suggestions on how to or has done name based virtual hosting in Apache? This is my setup:

-2 domain names from Register.com that I have them pointing to my IP.
-Linksys DSL/Cable Router that directs Port 80 to my Linux machine running Apache

I would like to be able to have the two domain names come in to the IP and then using the VirtualHost directive in httpd.conf direct each one to their individual DocumentRoot on the server. I've tried just using the example at the bottom of httpd.conf for virtual hosting but I think maybe since I have the router it's not passing everything to the machine??

Any suggestions? Thanks!
 

Valien

Junior Member
Jun 1, 2001
4
0
0
Hey! I know exactly what you are trying to do. I have 3 domains running off my cable modem using Virtual servers on my Apache box.

I don't have the specifs right off hand right now as I'm headed out the door, but if you email me (sto@chumpmonkey.com) i'll send you the info you need.

HTH.

~Valien
 

markjrubin

Golden Member
Jan 17, 2000
1,419
0
0
When you do find the specifics, can you post them here, in addition to emailing smr?

Mark
 

blstriker

Golden Member
Oct 22, 1999
1,432
0
0
Everything should be passed through the router to the server. It's your server which isn't differeniating between the two.
 

smr

Junior Member
Jun 1, 2001
12
0
0
I've tried a few things and I think maybe it's a configuration problem...Here's what I tried:

<VirtualHost *>
ServerAlias mydomain.com www.mydomain.com
DocumentRoot /home/bob/public_html
</VirtualHost>

<VirtualHost *>
ServerAlias mydomain2.com www.mydomain2.com
DocumentRoot /home/joe/public_html
</VirtualHost>

What this did is redirect request to www.mydomain.com to /home/bob/public_html rather than Apache's default location of /home/httpd/html (this is good!) BUT when I tried accessing www.mydomain2.com it also went to /home/bob/public_html and not /home/joe/public_html. I figured it must be because of the * in the VirtualHost tag so I tried the following:

<VirtualHost www.mydomain.com>
ServerAlias mydomain.com www.mydomain.com
DocumentRoot /home/bob/public_html
</VirtualHost>

<VirtualHost www.mydomain2.com>
ServerAlias mydomain2.com www.mydomain2.com
DocumentRoot /home/joe/public_html
</VirtualHost>

When I tried requesting either domain name it now brings me into Apache's default location of /home/httpd/html and not into the DocumentRoot I specified...

Any Suggestions?
 

Valien

Junior Member
Jun 1, 2001
4
0
0
Hey folks.

Sorry for the delay in replying. Been quite busy past few days.

Anyways, here's my setup.

Linksys BEFSR41 Router connecting 2 pc's internally to my @home account. One of my PC's is a dedicated webserver (albeit only running Win98 + Apache right now). I have 3 domains hosted on that PC though and am using Apache's virtual host directives to direct incoming traffic to the right website.

Here's what my httpd.conf file is...

ServerName -- this needs to be your primary site.
DocumentRoot -- Mine is set to the default, as I don't really use this directive.

here's the good part...

NameVirtualHost -- needs to be IP address of your pc (should be a static, internal, non-routable address [e.g. 192.168.x.x or something])

<VirtualHost 192.168.x.x>
DocumentRoot &quot;C:/ApacheGroup/Apache/<your web server root>&quot;
ServerAdmin <admin email@yoursite.com
ServerName <www.yoursite.com>
ErrorLog logs/<your site logs.log>
CustomLog logs/<your site logs.log> common
</VirtualHost>

and repeat this for all your sites. Only thing that should change is your DocumentRoot, ServerName, and Log file names.

Stop and Restart Apache and it should work fine. Oh, make sure you are forwarding port 80 from that specific box via your Linksys router.

This should take care of you.

Let me know if it doesn't and we'll see if we can figure it out.

~Valien
www.chumpmonkey.com
www.clana3d.org
 

Valien

Junior Member
Jun 1, 2001
4
0
0


<< Everything should be passed through the router to the server. It's your server which isn't differeniating between the two. >>



Hey, i like your dsl/cable website. Nice information. :)
 

blstriker

Golden Member
Oct 22, 1999
1,432
0
0
Thanks, too bad my site doesn't have any Apache info yet. Hopefully it'll get added soon.
 

smr

Junior Member
Jun 1, 2001
12
0
0
I tried what Valien suggested and got the same results as before:
My settings are:

<VirtualHost 192.168.1.101>
DocumentRoot /home/bob/public_html
ServerName www.mydomain.com
</VirtualHost>

<VirtualHost 192.168.1.101>
DocumentRoot /home/joe/public_html
ServerName www.mydomain2.com
</VirtualHost>

Same as before, when I try to access either one it just puts me into /home/bob/public_html. So mydomain2.com lands me in /home/bob/public_html and not in /home/joe/public_html

Anyone have a suggestion as to why this is happening?


Thanks,

Steve