LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 03-29-2007, 09:45 PM   #1
Poetics
Senior Member
 
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181

Rep: Reputation: 49
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
 
Old 03-29-2007, 11:22 PM   #2
ApachePadowan
LQ Newbie
 
Registered: Apr 2005
Location: FL
Distribution: Fedora Core 10
Posts: 25

Rep: Reputation: 15
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.
 
Old 03-29-2007, 11:28 PM   #3
Poetics
Senior Member
 
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181

Original Poster
Rep: Reputation: 49
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.

Last edited by Poetics; 03-29-2007 at 11:31 PM.
 
Old 03-30-2007, 03:50 PM   #4
Poetics
Senior Member
 
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181

Original Poster
Rep: Reputation: 49
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!
 
Old 03-31-2007, 11:28 PM   #5
ApachePadowan
LQ Newbie
 
Registered: Apr 2005
Location: FL
Distribution: Fedora Core 10
Posts: 25

Rep: Reputation: 15
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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache and IP - Based virtual Hosting shawnbishop Linux - Software 2 10-27-2006 09:56 AM
Config file for Apache name-based virtual hosting mnm_mc Linux - Software 5 03-22-2006 03:29 AM
name based virtual hosting jkmartha Linux - Software 4 08-04-2005 09:21 AM
Trouble with Named based Virtual hosting in Apache 2 IanChristie Linux - Networking 16 11-07-2003 02:04 PM
Setting default foreign language for 1 site when virtual hosting. dsiguy Linux - General 0 05-13-2003 11:41 AM


All times are GMT -5. The time now is 09:12 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration