Linksys DSL/Cable Router and Virtual Hosting in Apache Problem

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 into 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!
 

guaraguao

Member
May 21, 2001
159
0
0
I have exactly the same setup working perfectly.

OK, first of all, make sure the router is correctly forwarding port 80. Troubleshoot.
Try to access the server from the lan. if that doesn't work, than you know the problem is your server and not the router.

Here's what I do:

First, I setup the first, default virtual host; if the request doesn't match anything else, than the user sees this.

<VirtualHost *>
ServerAlias sebaz.homeip.net
DocumentRoot /usr/local/www/data
</VirtualHost>

Than, I setup the individual virtual hosts.

<VirtualHost *>
ServerAlias guaraguao.net www.guaraguao.net
ServerPath /guaraguao.net/
DocumentRoot /usr/local/www/data/guaraguao.net
</VirtualHost>

<VirtualHost *>
ServerAlias example.com www.example.com
ServerPath /example.com/
DocumentRoot /usr/local/www/data/example.com
</VirtualHost>


Notice the &quot;ServerPath&quot;.
What this does is sets up a virtual subdirectory under your main virtual host.
In other words, if someone wants to hit &quot;guaraguao.net&quot;, but their browser isn't current (ie, doesn't send necessary data for virtual hosting to work), than they'll get redirected to sebaz.homeip.net. From there, they can click the link to &quot;sebaz.homeip.net/guaraguao.net/&quot;, which will take them to the same place as guaraguao.net. Pretty nifty, huh?

You can find a boatload of info at the virtual hosting howto, located at linuxdoc.org


good luck,
Sebastian
 

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?


 

guaraguao

Member
May 21, 2001
159
0
0
well, first of all, the <VirtualHost *> part specifies the INTERFACE, not the site, so you'll want to leave it at *, otherwise it won't work as you want it.

I know this sounds dumb, but did you RESTART the server after making the required changes the first time around?
 

smr

Junior Member
Jun 1, 2001
12
0
0
Yes, I've restarted the server each time I've made a change...
 

smr

Junior Member
Jun 1, 2001
12
0
0
I tried switching back to the original configuration and restarting again:
<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>


But it seems like it's just going to the first one it finds in the list.... mydomain.com and mydomain2.com both go to /home/bob/public_html

I noticed you have ServerAlias in yours? What does that do?
 

smr

Junior Member
Jun 1, 2001
12
0
0
Sorry about that....I meant to say what does ServerPath do, not ServerAlias.... But I guess it will be easier to RTFM then ask...thought maybe leaving it out was causing the second one not to be recognized. Thanks for the other tips though...still no progress from my last posting..