Jump to content

Leading Community for Usability, Search Engine Marketing,
Social Networking, Site Planning & Web Site Development, Since 1998


Photo

Host multiple sites on one server with Apache


  • Please log in to reply
36 replies to this topic

#1 Andy

Andy

    Mach 1 Member

  • Members
  • 492 posts

Posted 30 January 2003 - 06:44 AM

Thought i'd share this with you.

I have my own webserver on a 1 Megabit line, at the moment I have 2 websites, and use Apache 2.

Manuals seem to make things complicated os here's a siomple guide on how to do it.

First of all you'll need to edit the httpd.conf file, this can be found in your Apache directory, and then in the conf subdirectory, sor example this is where mine is:
C:apacheconfhttpd.conf

The file is well commented, anything that has a # before it is a comment, so you can comment lines out you don't need or add comments to help you.

The area of the file we will be looking at, is usually at the very bottom of the file, Section 3: Virtual Hosts.

#

# Use name-based virtual hosting.

#

#NameVirtualHost *



#

# VirtualHost example:

# Almost any Apache directive may go into a VirtualHost container.

# The first VirtualHost section is used for requests without a known

# server name.

#

#<VirtualHost *>

#    ServerAdmin webmaster@dummy-host.example.com

#    DocumentRoot /www/docs/dummy-host.example.com

#    ServerName dummy-host.example.com

#    ErrorLog logs/dummy-host.example.com-error_log

#    CustomLog logs/dummy-host.example.com-access_log common

#</VirtualHost>


The above is the sample VirtualHost out of the httpd.conf file, the entire thing is commented out, as from this server VirtualHosts are not been used.

For each site you want to setup you have to create a VirtualHost, the first virtual host is the default, e.g if i do, http://80.194.49.33 that is not specifying a website, so the default one is displayed, which in my case is www.whittnet.co.uk.

Something i have noticed is, you have to create two, entries for one site, one for http://www.coolchip-computers.co.uk/ and one for http://coolchip-computers.co.uk.

This is because if you don't have an entry for the one without the www, it will show the default site, as it has no record of just coolchip-computers.co.uk.

For every VirtualHost you need to put the information within a Virtaul host tag, <VirtualHost *> options goes here </VirtualHost>.

The most common options are:
ServerAdmin,DocumentRoot,ServerName.
ServerAdmin #AdminsEmailAddress

DocumentRoot #DocumentRoot e.g c:apachehtdocsdomain1

ServerName #servers FullyQualifiedDomainName e.g www.whittnet.co.uk
Example:

<VirtualHost *>

    ServerAdmin andy@somewhere.com

    DocumentRoot e:htdocswhittnet

    ServerName www.whittnet.co.uk

</VirtualHost>

Int the above notice i did, www. So i'd have to create another without the www, example:
<VirtualHost *>

    ServerAdmin andy@somewhere.com

    DocumentRoot e:htdocswhittnet

    ServerName whittnet.co.uk

</VirtualHost>

To add another VirtualHost just follow the above.

Once you have edited the file you have to restart the Apache service, this can be done by using the apache control panel or by the services MMC snapin in your administrative tools.

The below example shows my VirtualHost setup:
<VirtualHost *>

    ServerAdmin andy@somewhere.com

    DocumentRoot e:htdocswhittnet

    ServerName whittnet.co.uk

</VirtualHost>



<VirtualHost *>

    ServerAdmin andy@somewhere.com

    DocumentRoot e:htdocswhittnet

    ServerName www.whittnet.co.uk

</VirtualHost>



<VirtualHost *>

    ServerAdmin andy@somewhere.com

    DocumentRoot e:htdocscoolchip-computers

    ServerName www.coolchip-computers.co.uk

    #RewriteEngine On

    #RewriteRule ^forum/(.*).html(.*)/$ /forum.php?forumID=$1

</VirtualHost>



<VirtualHost *>

    ServerAdmin andy@somewhere.com

    DocumentRoot e:htdocscoolchip-computers

    ServerName coolchip-computers.co.uk

    #RewriteEngine On

    #RewriteRule ^forum/(.*).html(.*)/$ /forum.php?forumID=$1

</VirtualHost>

note in the above example the rewrite rules, rewrite rules can be applied to avirtual host, at the moment, i'm having some probs with mine so there commented out.

Hope this has been helpful.


Extra Documentation:
[list]

#2 themover

themover

    New To Community

  • Members
  • 1 posts

Posted 30 March 2003 - 11:52 AM

Im having problems with apache virtual hosting. Apache will only host the site that is listed in the main server configuration of DocumentRoot. If I change the DocumentRoot folder to the second sites folder then that site will come up. Its as if the virtual hosts section is not working at all. Also, the NameVirtualHost line is uncommented, both sites have FQDN, and DNS is properly configured. Helppppppppppp!

#3 DianeV

DianeV

    Honored One Who Served Moderator Alumni

  • Hall Of Fame
  • 7213 posts

Posted 30 March 2003 - 12:06 PM

Okay, I'm no pro at this, but I found this in my httpd.conf file:


# The NameVirtualHost directive is a required directive

# if you want to configure name-based virtual hosts.



NameVirtualHost 111.222.333.444:*



# VirtualHost: Allows the daemon to respond to requests for

# more than one hostname.

Then, of course, as Andy has so helpfully pointed out, you must have the VirtualHost entries, but it sounds like you already do.

And welcome to the forums!

#4 njgMike99

njgMike99

    Ready To Fly Member

  • Members
  • 23 posts

Posted 08 April 2003 - 11:41 AM

Hi,

I am also having the same problem with multiple domains. U am using Linux Mandrake 9.1, Apache 2.0.44 and BIND 9

I know my DNS works for the subdomain db.okboss.com address at my domain www.okboss.com cause I did test at sam spade. And it reports my ip address ok.

My problem is that I added the virtual host below and my web server keeps sending me to the default page instead. I have check my logs and I can't seem to find any reference to the problem. Please help. Should I have a _default_ server configured if using virtual domains?

Here is my Vhosts.conf
NameVirtualHost 66.11.174.82

<VirtualHost 66.11.174.82>

       ServerName www.okboss.com

       ServerAlias okboss.com *.okboss.com

       DocumentRoot /var/www/html

</VirtualHost>

<VirtualHost 66.11.174.82>

    DocumentRoot /var/www/html/php/phpmyadmin

    ServerName db.okboss.com

    ErrorLog logs/db.okboss.com-error_log

    CustomLog logs/db.okboss.com-access_log common

</VirtualHost>

I have tried to use NameVirtualHost * but I still get the same results. Has anyone seen this before?

Mike :P [/code][/url]

#5 Andy

Andy

    Mach 1 Member

  • Members
  • 492 posts

Posted 08 April 2003 - 11:48 AM

Just a thought but put your subdomain before your domain one in your conf file, maybe it goes on some kind of priority.

So it comes in and cos your coming in on that domain thats why it goes to your other site.

NameVirtualHost 66.11.174.82 

 

<VirtualHost 66.11.174.82> 

    DocumentRoot /var/www/html/php/phpmyadmin 

    ServerName db.okboss.com 

    ErrorLog logs/db.okboss.com-error_log 

    CustomLog logs/db.okboss.com-access_log common 

</VirtualHost>

<VirtualHost 66.11.174.82> 

       ServerName www.okboss.com 

       ServerAlias okboss.com *.okboss.com 

       DocumentRoot /var/www/html 

</VirtualHost>

worth a stab, but i could be making sh*t up.

:D

#6 njgMike99

njgMike99

    Ready To Fly Member

  • Members
  • 23 posts

Posted 08 April 2003 - 01:01 PM

That did it!!! :D :D :D

I reversed the order for the virtual servers and it did the trick!!! I have been work ing on that for 2 days now! :?


NameVirtualHost 66.11.174.82

<VirtualHost 66.11.174.82>

       ServerName webmail.okboss.com

       #ServerAlias okboss.com *.okboss.com

       DocumentRoot /var/www/html/squirrel

</VirtualHost>

<VirtualHost 66.11.174.82>

#ServerAdmin webmaster@dummy-host.example.com

    DocumentRoot /var/www/html/db

    ServerName db.okboss.com

    ErrorLog logs/db.okboss.com-error_log

    CustomLog logs/db.okboss.com-access_log common

</VirtualHost>

<VirtualHost 66.11.174.82>

       ServerName www.okboss.com

       ServerAlias okboss.com *.okboss.com

       DocumentRoot /var/www/html

</VirtualHost>


Thank you very very very much! Now all I have to do is create a virtual host for a different domain altogether. Yikes.. I hope its the same process. I'll Let you all know how I did. :)

Thanks again Andy, all the way from Canada![/code]

#7 Andy

Andy

    Mach 1 Member

  • Members
  • 492 posts

Posted 08 April 2003 - 03:44 PM

Your welcome dude, yeh keep us posted!

:D

#8 Viper

Viper

    Unlurked Energy

  • Members
  • 3 posts

Posted 27 April 2003 - 02:31 AM

Just found this, and wanted to say thx for some good information!

I do have one question/problem tough...

When I setup a second domain I get some sort of a MySql problem with one of my forums.

I have these 2 sites that Im working on: http://ranger.servegame.com and http://df-news.com/

http://ranger.servegame.com works well.

http://df-news.com/ only works like this...

If I have it like this http://www.df-news.com/ I get problems. Why does the www give me problems? Can it be fixed?

#9 Black_Knight

Black_Knight

    Honored One Who Served Moderator Alumni

  • Hall Of Fame
  • 9293 posts
  • Twitter:http://twitter.com/#!/Ammon_Johns
  • Facebook:http://www.facebook.com/ammon.johns

Posted 27 April 2003 - 02:40 AM

If I have it like this http://www.df-news.com/  I get problems. Why does the www give me problems? Can it be fixed?


Make sure you've specified the www subdomain in your setup
      ServerName www.df-news.com

       ServerAlias df-news.com *.df-news.com



#10 Viper

Viper

    Unlurked Energy

  • Members
  • 3 posts

Posted 27 April 2003 - 02:52 AM

Wow that was fast thx, this is how I have my config. Thanks for looking at it...

NameVirtualHost www.df-news.com





<VirtualHost www.df-news.com>

    ServerAdmin admin@df-news.com

    DocumentRoot C:EasyServwww

    ServerName www.df-news.com

    ErrorLog logs/dummy-host.example.com-error_log

    CustomLog logs/dummy-host.example.com-access_log common

</VirtualHost>



<VirtualHost ranger.servegame.com>

    ServerAdmin viper@rtfbase.com

    DocumentRoot C:ranger

    ServerName ranger.servegame.com

    ErrorLog logs/dummy-host.example.com-error_log

    CustomLog logs/dummy-host.example.com-access_log common

</VirtualHost>









#11 Viper

Viper

    Unlurked Energy

  • Members
  • 3 posts

Posted 27 April 2003 - 03:09 AM

Think I need additional information on how to solve it... :cry:

Dont know how to use your snipe of code you posted (I have tried).

#12 njgMike99

njgMike99

    Ready To Fly Member

  • Members
  • 23 posts

Posted 28 April 2003 - 06:40 AM

Ok.. Now Im trying to use SSL on one of my sites but when I put the SSL directives into the virtual hosts the whole site changes to SSL instead of the individual virtual hosts.


# ----------------------- WEBMAIL OKBOSS ------------------

<VirtualHost 66.11.174.82>

       ServerName webmail.okboss.com

       #ServerAlias okboss.com *.okboss.com

       DocumentRoot /var/www/html/squirrel

       ErrorLog syslog

       LogLevel info

      #SSLEngine on

      #SSLProtocol +SSLv2 +SSLv3

      #SSLCertificateFile /etc/ssl/apache/server.crt

      #SSLCertificateKeyFile /etc/ssl/apache/server.key

</VirtualHost>



# ----------------------- OKBOSS.COM ------------------

<VirtualHost 66.11.174.82>

       ServerName www.okboss.com

       ServerAlias okboss.com *.okboss.com

       LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i""

       TransferLog /var/log/httpd/access_log

       DocumentRoot /var/www/html

SSLEngine off

</VirtualHost>


Any ideas why this might be happening?

#13 njgMike99

njgMike99

    Ready To Fly Member

  • Members
  • 23 posts

Posted 30 April 2003 - 11:47 AM

I figured it out! Although I didn't find any clear documentations on it I managed to make it work like so...

Apache 2.0.45
How to create SSL Virtual Hosts and NON-SSL virtual host on one server.

Vhosts.conf - Or possibly Httpd2.conf

NameVirtualHost 66.11.174.82:443

NameVirtualHost 66.11.174.82:80



# ----------------------- WEBMAIL OKBOSS SSL------------------

<VirtualHost 66.11.174.82:443>

       ServerName webmail.okboss.com

       DocumentRoot /var/www/html/squirrel

       SSLEngine on

       SSLCertificateFile /etc/ssl/apache/server.crt

       SSLCertificateKeyFile /etc/ssl/apache/server.key

</VirtualHost>

# ----------------------- DB OKBOSS ------------------

<VirtualHost 66.11.174.82:80>

    DocumentRoot /var/www/html/database

    ServerName db.okboss.com

    ErrorLog logs/db.okboss.com-error_log

    CustomLog logs/db.okboss.com-access_log common

</VirtualHost>



# ----------------------- SURPRISEMYWIFE.COM ------------------

<VirtualHost 66.11.174.82:80>

       ServerName surprisemywife.com

       ServerAlias surprisemywife.com *.surprisemywife.com

       DocumentRoot /var/www/html/surprisemywife

	LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i""

	TransferLog /var/log/httpd/surprisemywife_access_log

</VirtualHost>



# ----------------------- SURPRISEMYWIFE.CA ------------------

<VirtualHost 66.11.174.82:80>

       ServerName surprisemywife.ca

       ServerAlias surprisemywife.ca *.surprisemywife.ca

       DocumentRoot /var/www/html/surprisemywife

       LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i""

       TransferLog /var/log/httpd/surprisemywife_access_log

</VirtualHost>



# ----------------------- OKBOSS.COM ------------------

<VirtualHost 66.11.174.82:80>

       ServerName www.okboss.com

       ServerAlias okboss.com *.okboss.com

       LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i""

       TransferLog /var/log/httpd/access_log

       DocumentRoot /var/www/html

</VirtualHost>



# ----------------------- OKBOSS.COM SSL ------------------

<VirtualHost 66.11.174.82:443>

       ServerName www.okboss.com

       ServerAlias okboss.com *.okboss.com

       LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i""

       TransferLog /var/log/httpd/access_log

       DocumentRoot /var/www/html

       SSLEngine on

       SSLProtocol +SSLv2 +SSLv3

       SSLCertificateFile /etc/ssl/apache/server.crt

       SSLCertificateKeyFile /etc/ssl/apache/server.key

</VirtualHost>


Hope this helps anyone other there.. 8)

[/b]

#14 DianeV

DianeV

    Honored One Who Served Moderator Alumni

  • Hall Of Fame
  • 7213 posts

Posted 30 April 2003 - 03:52 PM

I'm sure it will. Thanks for the information!

#15 beno

beno

    Unlurked Energy

  • Members
  • 3 posts

Posted 31 August 2003 - 02:15 PM

This tutorial has been a really helpful tool in getting apache configured to host several virtual sites on a single IP. I have a buddy who is trying to host 4 sites on a single IP, and currently has 4 sites being forwarded to that address (209.50.25.178) over a static DSL connection, acting server is running Windows 200 Pro.

After reading this, I now have 2 of the sites working, the main site (www.stunttours.com), and the first virtual site listed in my httpd.conf file (www.comedynetworkonline.com). The other virtual sites appear to all be going to the first virtual site I have listed. Anyone have any clues as to why this might be happening? Here is my code:


NameVirtualHost 209.50.25.178:80

#

# VirtualHost example:

# Almost any Apache directive may go into a VirtualHost container.

# The first VirtualHost section is used for requests without a known

# server name.

#



<VirtualHost 209.50.25.178>

    ServerAdmin dbaier@stunttours.com

    DocumentRoot "E:/comedy"

    ServerName www.comedynetworkonline.com

    serverAlias *.comedynetworkonline.com

    ErrorLog logs/comedy_error_log

#   CustomLog logs/dummy-host.example.com-access_log common

</VirtualHost>



<VirtualHost 209.50.25.178>

    ServerAdmin dbaier@stunttours.com

    DocumentRoot "E:/concert"

    ServerName www.concertservicenetwork.com

    ServerAlias *.concertservicenetwork.com

    ErrorLog logs/concert_error_log

#   CustomLog logs/dummy-host.example.com-access_log common

</VirtualHost>



<VirtualHost 209.50.25.178>

    ServerAdmin dbaier@stunttours.com

    DocumentRoot "E:/celebrity"

    ServerName www.celebrityattractionsnetwork.com

    ErrorLog logs/celebrity_error_log

#   CustomLog logs/dummy-host.example.com-access_log common

</VirtualHost>



<VirtualHost 209.50.25.178>

    ServerAdmin dbaier@stunttours.com

    DocumentRoot "E:/stunt"

    ServerName www.stunttours.com

    ErrorLog logs/stunt_error_log

#   CustomLog logs/dummy-host.example.com-access_log common

</VirtualHost>


I have been searching on the net for hours for some sort of tutorial or post that might explain what I don't have set up right, but haven't been able to find anything yet. Thanks in advance for any advice you might have, it is truly appreciated

#16 DianeV

DianeV

    Honored One Who Served Moderator Alumni

  • Hall Of Fame
  • 7213 posts

Posted 31 August 2003 - 07:57 PM

This is set up a little differently than my own httpd.conf, but I note that your first two examples include a ServerAlias, and the others don't. Have you tried specifying ServerAlias for the rest?

#17 beno

beno

    Unlurked Energy

  • Members
  • 3 posts

Posted 31 August 2003 - 10:28 PM

I'm heading over to his place in a little bit here, I'll give that a shot (specifying aliases for the other 2 servers), I didn't know whether or not the server alias definitions were necessary so I'll give that a try! Thanks a million for the input.

#18 beno

beno

    Unlurked Energy

  • Members
  • 3 posts

Posted 03 September 2003 - 07:30 PM

well, I updated all sections so they all contain the alias, but I can still only get those first 2 sites to come up. Any other suggestions? Thanks for your help.

#19 pvclink

pvclink

    Ready To Fly Member

  • Members
  • 10 posts

Posted 03 October 2003 - 05:10 AM

Hello,


Hi its me again

sure i known there's a lot of people would help me thanks a lot in addvance

problem

I could not display my new documentRoot on my new vertual domains?

#20 bragadocchio

bragadocchio

    Honored One Who Served Moderator Alumni

  • Hall Of Fame
  • 15634 posts

Posted 03 October 2003 - 06:29 AM

Hi pvclink

Welcome to the forums.

I saw your question in the other post about having a site point at both http://www.mysite.com and http://mysite.com.

Check with your host, if someone is hosting your site. They should be able to tell you if they can switch that.

If you are on an apache server, and have access to use an htaccess file, it may be something that you can change. But, check with your host first, if you are hosted.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users