LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Apache Virtual Name-Based Hosting and Default Site (https://www.linuxquestions.org/questions/linux-server-73/apache-virtual-name-based-hosting-and-default-site-541782/)

Poetics 03-29-2007 09:45 PM

Apache Virtual Name-Based Hosting and Default Site
 
Good afternoon!

I've searched through the LQ.org archives and though I have found threads detailing similar problems, I haven't found a satisfactory answer to my current quandry.

I have two domains hosted off of one IP address (1.2.3.4), and httpd -S reports that the configuration file is successful. One domain is working just fine, as it always has, but the second virtual host isn't ever displayed -- just the first (or "default") one.

Code:

NameVirtualHost 1.2.3.4:80

<VirtualHost 1.2.3.4:80>
    ServerAdmin poetics@firstdomain.com
    DocumentRoot /var/www/sites/firstdomain.com
    ServerName firstdomain.com
    ErrorLog logs/firstdomain.com-error_log
    CustomLog logs/firstdomain.com-access_log common
</VirtualHost>

<VirtualHost 1.2.3.4:80>
    ServerAdmin poetics@seconddomain.com
    DocumentRoot /var/www/sites/seconddomain.com
    ServerName seconddomain.com
    ErrorLog logs/seconddomain.com-error_log
    CustomLog logs/seconddomain.com-access_log common
</VirtualHost>

I have the DNS setup correctly, with A records for both firstdomain.com and seconddomain.com both pointing to 1.2.3.4 -- however, when one browses to seconddomain.com they reach firstdomain.com

Results of httpd -S:
Code:

VirtualHost configuration:
1.2.3.4:80      is a NameVirtualHost
        default server firstdomain.com (/etc/httpd/conf/httpd.conf:1019)
        port 80 namevhost firstdomain.com (/etc/httpd/conf/httpd.conf:1019)
        port 80 namevhost seconddomain.com (/etc/httpd/conf/httpd.conf:1027)
Syntax OK

Any suggestions?
-- Poetics

ApachePadowan 03-29-2007 11:22 PM

Try substituting the IP to a * in your VirtualHost containers.

Example:

<VirtualHost *:80>
...
...
...
</VirtualHost>

I had a similar problem in the past and setting up like this resolved it.

Poetics 03-29-2007 11:28 PM

Will that affect the fact that I have another website hosted on 1.2.3.5? I have the two aforementioned virtual hosts and another using IP-based hosting (which has never had an issue). I'll give that a try and report back. Thanks for the suggestions!


Edit: No, it killed my IP-based host with it, and still didn't allow me to get to seconddomain.com either.

Poetics 03-30-2007 03:50 PM

Aha! Discovery at last. When one types in www.domain.com Apache recognizes it as a seperate entity than just domain.com -- I was trying www.seconddomain.com and it wasn't working. Now that I've made a second entry for both firstdomain.com and seconddomain.com for www. it works beautifully.

Odd that no howto I've ever found had mentioned this!

ApachePadowan 03-31-2007 11:28 PM

Glad it worked out...

Here's another suggestion: add the ServerAlias directive to your virtualhost container for the domains rather than creating a whole new virtualhost.
Code:

#Domain 1
<VirtualHost ip:port>
ServerName mydomain.com
ServerAlias www.mydomain.com
Other directives, etc.
</VirtualHost>
#Domain 2
<VirtualHost ip:port>
ServerName otherdomain.com
ServerAlias www.otherdomain.com
Other directives, etc.
</VirtualHost>

And make sure your DNS is setup to treat www.mydomain.com and www.otherdomain.com as aliases as opposed to hosts...

Happy web-serving!


All times are GMT -5. The time now is 06:01 AM.