LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Virtual Hosts - whats wrong (https://www.linuxquestions.org/questions/linux-newbie-8/virtual-hosts-whats-wrong-40523/)

Cynthia Blue 01-06-2003 06:06 PM

Virtual Hosts - whats wrong
 
Here is how I have my virtual hosts set up for my primary and secondary domain name. It is not directing the 2ndary domain name to the correct directory. I swear I've tried every port/IP/directory combination that exists... gah. What is wrong here? It is insisting I have a Default Virtual Host, and when I change that to specify port 80 apache will not restart. I swear this should work...?

Red Hat 8.

Code:

#
# Use name-based virtual hosting.
#
NameVirtualHost 888.88.88.88
   
#
# Virtual hosts
#

# Virtual host Default Virtual Host
<VirtualHost *:80>
        DocumentRoot /var/www/html
        ServerAdmin cyn@cynthiablue.net
        ServerName _default_:80
        DirectoryIndex index.php index.html index.htm index.shtml
        LogLevel debug
        HostNameLookups off
</VirtualHost>

# Virtual host domain2.com
<VirtualHost 888.88.88.88>
        DocumentRoot /var/www/html/ud
        ServerAdmin cyn@cynthiablue.net
        ServerName www.domain2.com
        ServerAlias domain2.com
        DirectoryIndex index.php index.html index.htm index.shtml
</VirtualHost>


te_conway 01-06-2003 06:14 PM

The wildcard in the 1st virtual host setup accepts all requests. Since there is no ServersAlias it processes everything.
Put a ServerName and ServerAlias in BOTH definitions to differentiate between them right after DocumentRoot.
You can use <VirtualHost *> for both setups

te_conway 01-06-2003 06:16 PM

PS: the ServerName should be a valid domain that points to your IP address.

Torm3nt 01-06-2003 06:32 PM

hmmm
 
Firstly:

NameVirtualHost *

It doesn't matter if you have <VirtualHost *>, just as long as you specify the ServerName.

ie.

Code:

### www.example1.com ###
<VirtualHost *>
  DocumentRoot /home/www/example1.com
  ServerAdmin admin@example1.com
  ServerName www.example1.com
</VirtualHost>

### www.example2.com.au ###
<VirtualHost *>
  DocumentRoot /home/www/example2
  ServerName www.example2.com.au
</VirtualHost>

### www.example3.com.au ###
<VirtualHost *>
  ServerAdmin webmaster@example3.com.au
  DocumentRoot /home/www/example3.com.au
  ServerName example3.com.au
</VirtualHost>

Remember that namebased virtual hosting is based off the client browser. It pulls the url it's after from the headers I believe. Therefore, it's not always accurate ( users of older browsers ), but will be fine for 99% of users that hit your site(s).

The above configuration works fine for the 75+ sites i have setup on my linux box, so it should work fine for you. To test domains that don't exist by your account, alter your hosts file in:

windows > system32 > drivers > etc > hosts

and enter:

[ipaddress] domainname.com

then, use "domainname.com" in your browser to test it.

Hope that helps

Cynthia Blue 01-07-2003 10:22 AM

Thanks for the advice... :) I gave up last night, I will go home and try the changes tonight.

Torm3nt 01-07-2003 04:19 PM

not a problem. If you need any more help, continue posting on this thread. :)

Cynthia Blue 01-07-2003 08:03 PM

Okay, this is what I have now... seems that my utahdogs.com domain name hangs for a while, then just stops without reaching the correct directory. It still stays on my main domain name's page. :( I did add the domain name to the /etc/hosts file as well.

Code:

# Use name-based virtual hosting.
NameVirtualHost *

# Virtual host cynthiablue.net
<VirtualHost *>
        DocumentRoot /var/www/html
        ServerAdmin cyn@cynthiablue.net
        ServerName www.cynthiablue.net
        ServerAlias cynthiablue.net
        DirectoryIndex index.php index.html index.htm index.shtml
 </VirtualHost>

# Virtual host utahdogs.com
<VirtualHost *>
        DocumentRoot /var/www/html/ud
        ServerAdmin cyn@cynthiablue.net
        ServerName www.utahdogs.com
        ServerAlias utahdogs.com
        DirectoryIndex index.php index.html index.htm index.shtml
</VirtualHost>


Cynthia Blue 01-07-2003 08:25 PM

Waiting patiently seemed to help. :) Hung for a while, now it works.. good thing for that tv break. :)

Thanks for the help. :)

Torm3nt 01-07-2003 09:03 PM

hehe.

no problems.


All times are GMT -5. The time now is 05:18 AM.