freebsdzine.org
If bankers can count, how come they have eight windows and only four tellers?

[ Home  · Latest BSD News  · Site Statistics  · Wanted Articles  · Request an Article  · Submit an Article ]

Search freebsdzine.org

FreeBSD 'zine Polls

How did you find out about this site?

FreeBSD web site
Slashdot
BSD Today
Daemon News
IRC
FreeBSD mailing list(s)
word of mouth
a search engine
from moses

Results  · More polls


Sections
· Wanted articles
· Request an article
· Contribute
· Mailing lists
· About the site
· The staff
· Copyright info
· Privacy policy
· Change log
· Contact us

Resources
· The FreeBSD Project
· The FreeBSD Diary
· BSD Today
· Daemon News
· Daily Daemon News
· Slashdot BSD
· FreshPorts
· The FreeBSD Mall
· BSDVault
· The FreeBSD Browser
· GreasyDaemon.com
· iso-nix.com

FreeBSD Books
· Complete FreeBSD
· FreeBSD Handbook
· FreeBSD Corporate
Networker's Guide


Runs on FreeBSD
Virtual Servers Behind Cable/DSL
Terrance Young <[email protected]>

Introduction

I decided to write this article after hearing from a co-worker that he tried to serve multiple virtual servers behind his Cable/DSL router. He was doing this before he had his Cable/DSL router and said that the router was unable to do this. I knew that you should be able to serve multiple domains behind a single IP address and have it work with no problems. So, I set off to prove it. That's how freebsd.2y.net got started.

Now for some real content... doing this really wasn't very hard, and I got the virtual servers to work on the first try. I was already serving pages on my server from home, so changing it a bit was no problem.

Configuration

First, you should familiarize yourself with Apache and how to set it up. The defaults when installing FreeBSD works fine all you need to do is fine tune it a bit for virtual servers or whatever loads you may be handling. You can find documentation on Apache 1.3.x at http://httpd.apache.org/docs/. I already was serving web pages off of my PC behind a Umax 3000 Cable/DSL Router and was not having any difficulty with any pages or CGI. Here's what I did to get this working.

I set the BindAddress to * because this is used to tell the server which IP address to listen on. I use the * because this way I don't need to specify the external IP DHCP address or the internal non-routable address where I may have problems either way on certain functions.

Set the port you want your web server to listen on. You must make sure that you allow this port access from the outside on your Cable/DSL router unless you have your server in the DMZ where ALL ports are accessible.

Port 80

Don't forget to have a address to send e-mail for problems encountered with the server.

ServerAdmin [email protected]

You can comment out the ServerName directive since you won't need it if you're doing virtual hosts.

# ServerName freebsd.2y.net

The DocumentRoot directory is where your web pages live.

DocumentRoot "/usr/local/www/data"

Make sure the following is set to the same thing as your DocumentRoot directory.

<Directory "/usr/local/www/data">

This brings us to the virtual server configuration part of httpd.conf.

## Section 3: Virtual Hosts

We will be using name-based virtual hosts since we only have one IP address.

#
# Use name-based virtual hosting.
#
NameVirtualHost *

Now we can create our virtual hosts. The first one is your "default server". The ServerAlias directive can be used to assign additional names to a directory. In this case, hoku.dyn.dhs.org will read from the same directory as hoku.2y.net and, in turn, load the same web pages.

# 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 [email protected]
# 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>

# hoku.2y.net - Default Server or lookup via IP
<VirtualHost *>
ServerAdmin [email protected]
DocumentRoot /usr/local/www/data
ServerName hoku.2y.net
ServerAlias hoku www.hoku.2y.net hoku.dyn.dhs.org
</VirtualHost>

# FreeBSD.2y.net - Virtual Server being hosted on the same box.
<VirtualHost *>
ServerAdmin [email protected]
DocumentRoot /usr/local/www/data/virtual/freebsd
ServerName freebsd.2y.net
ServerAlias www.freebsd.2y.net
</VirtualHost>

Now that the configuration is complete, you need to restart Apache, which is done by running the following command as root:

# apachectl restart
Conclusion

Everything should work now, assuming that you have the proper DNS entries for your IP address. I happen to use the free DNS services from http://www.dhs.org/, but there are some other places that you can get this service from as well.

Although my box is a FreeBSD 4.2 machine running Apache 1.3.14, it should apply to any Apache server running at least the 1.3.x release or above. I am not an authority on Apache and the above mentioned changes in no way constitutes the best configuration that could be done with Apache. I am open to comments and suggestions, so if you have any, please feel free to email me at [email protected].

- Terrance

Return to the April 2001 Issue



Issues
2001
· April
· March
· February
· January

2000
· December
· August
· July
· June
· May
· April
· March
· February

1999
· January

Other issues from 1999 are available in the attic for now.

Other News
· Slashdot
· FreeBSD Diary
· BSD Today
· FreshPorts
· Daemon News
· OS Online
· Rootprompt
· Maximum BSD

Miscellaneous
· Jim's site

IRC
#freebsdzine
If you'd like to hang out with us and talk about the site, join us in #freebsdzine on Undernet.

Backend
You can add a list of our latest issue's articles to your site by using our RDF/RSS file. You can also add it to your My Netscape page, or add our slashbox once you log in over at Slashdot.

[ Home  · Latest BSD News  · Site Statistics  · Wanted Articles  · Request an Article  · Submit an Article ]

Copyright © 1998-2001 · The FreeBSD 'zine · All rights reserved.