LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 11-07-2004, 05:04 PM   #1
QtCoder
Member
 
Registered: Aug 2003
Location: USA
Distribution: Slackware 12.0 RC1
Posts: 129

Rep: Reputation: 15
Apache 2 defaulting to first virtual host


I know similar threads have been posted, but in order not to barge in on someone else's thread, I'm creating my own.

Ok, here's my situation:

I've got two domain names, sunshine-market.com and bluewillowherbs.biz. I'm serving both on a Mandrake 9.2 server with Apache 2. I'm using name-based virtual hosting. I've also got indirect access to my ISP's DNS servers so I can create my own zone files and have them put up.

Take a look at my conf files here (I've also included the zone files I'm using): -- URL removed... problem fixed --

When I'm at my server's console, or VNC'd into it, I go to localhost in my browser and I get the site for bluewillowherbs. Why does my primary server configuration not go into effect? It should be going to the sunshine-market site because sunshine-market is the primary host (it's not a vhost). The same happens when I go to the IP or www.sunshine-market.com remotely. Plus, I cannot resolve bluewillowherbs.biz anymore. Something is screwed up somewhere...

Tell me what I'm doing wrong!

PS -- I'm doing all my configuration based on Apache Server 2 Bible.

Last edited by QtCoder; 11-08-2004 at 05:16 PM.
 
Old 11-08-2004, 12:37 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
When you are using virtual hosts the first one will always be the default. Just add another virtual host for the site you want to be the default above the current one.
 
Old 11-08-2004, 05:08 PM   #3
QtCoder
Member
 
Registered: Aug 2003
Location: USA
Distribution: Slackware 12.0 RC1
Posts: 129

Original Poster
Rep: Reputation: 15
Should I just copy some of the directives from httpd2.conf to a new vhost container? To me that seems very redundant. Apache should be able to pick the hostname out of the HTTP headers and differentiate between the primary host and any vhosts. But, if that's what needs to be done, then I'll do it.

Thanks for the tip. I'll let you know how it works.
 
Old 11-08-2004, 05:15 PM   #4
QtCoder
Member
 
Registered: Aug 2003
Location: USA
Distribution: Slackware 12.0 RC1
Posts: 129

Original Poster
Rep: Reputation: 15
Ok, worked like a charm. How rediculous, IMHO. Oh well, whatever works! :-) I'm happy. Thanks.
 
Old 01-26-2005, 12:30 PM   #5
alejandroye
Member
 
Registered: May 2004
Location: SOUTH FLORIDA USA
Distribution: MANDRIVA / CENTOS
Posts: 146

Rep: Reputation: 15
QUESTION ABOUT VHOSTS.CONF

hello

I am trying to setup apache2 too, but I get confuse

I have to make change in Vhosts.conf when you adding the other domain?
if is like that can you tell me what I have to change in httpd2.conf and what is the change in Vhosts.conf
suppose we have :

1 IP address
2 Domain names domain1, domain2
and 2 zone
1 server w/ apache2
drake 10.1


thank you
 
Old 01-26-2005, 03:21 PM   #6
QtCoder
Member
 
Registered: Aug 2003
Location: USA
Distribution: Slackware 12.0 RC1
Posts: 129

Original Poster
Rep: Reputation: 15
You shouldn't have to make any changes in httpd2.conf to add a virtual host. There is a section in httpd2.conf that includes the vhosts.conf file -- it's set by default, and should look something like this:

Code:
###
### Virtual Hosts 
###
# We include different templates for Virtual Hosting. Have a look in the 
# vhosts directory and modify to suit your needs.
Include conf/vhosts/Vhosts.conf
#Include conf/vhosts/DynamicVhosts.conf
#Include conf/vhosts/VirtualHomePages.conf
The sites I am hosting are sunshine-market.com and bluewillowherbs.biz. Here's my Vhosts.conf:

Code:
NameVirtualHost 168.103.142.125:80
<VirtualHost 168.103.142.125:80>
  ServerName www.sunshine-market.com
  DocumentRoot "/var/www/html/www.sunshine-market.com"
  TransferLog logs/access_log
  ErrorLog logs/error_log
</VirtualHost>

<VirtualHost 168.103.142.125:80>
  ServerName www.bluewillowherbs.biz
  ServerAlias bluewillowherbs.biz
  DocumentRoot "/var/www/html/www.bluewillowherbs.biz"
  TransferLog logs/bluewillow-access.log
  ErrorLog logs/bluewillow-error.log
</VirtualHost>
The first directive, NameVirtualHost, tells Apache that you're using name based virtual hosting (preferable in most cases). This means that you can add virtual hosts under one IP address. The VirtualHost containers contain the configuration for each vhost. The first one I have refers to sunshine-market.com, which is the default domain on my system -- sunshine-market.com is the one I set up in httpd2.conf initially but as the answer to my first question above pointed out, I had to add a virtual host for it as well. The second container refers to bluewillowherbs.biz.

All I had to do was set up the directives for each vhost, like the server name, doc root, etc, and I just copied the directives from httpd2.conf for my sunshine-market.com vhost.

In your example case, the vhosts file should look a little like this:

Code:
NameVirtualHost your.ip.address:80
<VirtualHost your.ip.address:80>
  ServerName domain1
  DocumentRoot "/var/www/html/domain1"
  TransferLog logs/access_log
  ErrorLog logs/error_log
</VirtualHost>

<VirtualHost your.ip.address:80>
  ServerName domain2
  DocumentRoot "/var/www/html/domain2"
  TransferLog logs/domain2-access.log
  ErrorLog logs/domain2-error.log
</VirtualHost>
Of course, you can have different log file names and directory structures. Plus, you can add more directives to a certain vhost container to restrict access to certain folders for ex, or give cgi permissions to a folder, etc.

This link, http://httpd.apache.org/docs-2.0/vhosts/ , is directly from Apache's docs. It explains everything very well.

Good luck!

Last edited by QtCoder; 01-26-2005 at 03:23 PM.
 
Old 01-26-2005, 05:40 PM   #7
alejandroye
Member
 
Registered: May 2004
Location: SOUTH FLORIDA USA
Distribution: MANDRIVA / CENTOS
Posts: 146

Rep: Reputation: 15
o man you are the best, I really appreciate your help, people like you should be more in this forum, thank you

so, what I have to do in the begining of httpd2.conf that said:

----------------------
ServerRoot /etc/httpd/2.0
ServerName localhost
#LockFile /etc/httpd/httpd.lock
PidFile /var/run/httpd.pid
ErrorLog logs/error_log
LogLevel warn
DocumentRoot /var/www/html/dir1

---------------------

I have to change any of this?


thk a LOT
 
Old 02-16-2005, 07:43 PM   #8
QtCoder
Member
 
Registered: Aug 2003
Location: USA
Distribution: Slackware 12.0 RC1
Posts: 129

Original Poster
Rep: Reputation: 15
It's been almost a month since I replied. I didn't get any notice via email. Sorry about that.

Anyway... nope, you don' t have to change any of those directives in httpd2.conf. It's perfectly fine for them to be duplicated in the virtual host container.
 
  


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 - Name virtual host tisource Linux - Networking 5 03-03-2006 02:52 AM
Apache 2 Virtual host eckertc1 Linux - Software 6 03-22-2005 09:58 PM
Apache 2.0 Virtual Host? w0lfeyes Linux - Networking 1 05-03-2004 03:09 PM
Virtual host and apache Samspeed Linux - General 8 08-06-2003 07:41 AM
apache virtual host navinc Linux - Software 10 05-22-2003 12:16 PM


All times are GMT -5. The time now is 01:06 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