[thelist] localhost Apache virtual server config problem

Daniel J. Cody djc at starkmedia.com
Tue Jan 23 17:42:31 CST 2001


Hey Terry  -

Good questions! :)

First off, to answer your question the 'Listen' and 'BindAddress'
directives will work in your sitution because they're 'on' by default.
So what do I mean by 'on'? Glad you asked.. ;) (warning, in depth,
meandering dan type message ahead)

When you compile apache - or download a binary version as typical for
win32 - there are a number of defaults that get compiled in to your
final apache binary(httpd).  One of them is the 'Listen' directive that
by default is set to listen on port 80, the most commonly called port
for webservers. You could pass a different value into the actual source
code for apache if you wanted, so that by *default* it would listen on
port 9999; while you were building apache for example(this is with
source code, not the binary) you could say
[root at foo]# ./configure --prefix=/usr/local/apache/ --with-port=9999

and that would install apache in /usr/local/apache(i'm using Unix
variables here, but it applies to win32 as well) and the default port
would be 9999.

Now, you *could* have apache listen on port 80 as well, even though by
default it is listening on port 9999 in our example by adding the:

Listen 80

directive.. Basically, the 'Port' directive sets the default port that a
server or vhost will listen on. The 'Listen' directive is used if you
want to listen on an alternative port other than what you've already got
defined, *or* if you want to bind a *specific* IP address to a
*specific* - non default - port. Thats a whole other discussion though :)

The 'BindAddress' directive is the same way. When apache starts, it
grabs a list of all TCP/IP interfaces you've got enabled on your
computer, and unless you have it configured otherwise, will allow
requests from all of those interfaces. Another example:

Lets say I have a computer with 2 network cards and a modem. For
simplicity network interface card(NIC) 1 = 1.0.0.0 NIC2 = 2.0.0.0 and
modem = 3.0.0.0 when its 'on'.

If you don't specifically tell apache otherwise, it will use the
'BindAddress *' directive which will listen on all interfaces if they're
active. This could be a good or bad thing and if you have multiple IP
address' assigned to your computer, it can get really complicated(but
can be really powerful). If my computer has the 2 NIC's and the modem I
may not want people to be able to access my webserver from one of the
networks. Therefore, I'd put something like

BindAddress 2.0.0.0

in my httpd.conf file, *specifically* telling apache to only accept
traffic on that interface. This is pretty cool if you have a computer
hooked up to multiple networks(private and public for example) and don't
want anyone on the public(example) network to see you're running a
webserver. In fact, I have a linux box at home that does just this. It
only allows traffic to my internal private network even though its
hooked into the Internet as well.

At any rate, I'm getting off track :)

There are a hundred billion ways to configure apache with virtual hosts
when you use the 'Listen' 'Port' and 'BindAddress' directives. The best
I could think of is a hosting provider that has a server hosting 100
sites, 50 of them with their own IP and 50 that share an IP(lets assume
the server already has those 50 seperate IP's pointing at and is
accepting traffic on those interfaces). The abbreviated httpd.conf file
for that would look something like this:

BindAddress: *

#skiping a bunch of stuff, lets say our <virtualhost> section started #here:

Port 80		#what we're listening on by default
Listen 80		#just because

NameVirtualHost
1.1.1.1 #for name based vhosting, our shared IP

<VirtualHost 1.1.1.1>
ServerName host1.dan.com
irrelvant stuff pertaining to this discussion goes here..
</VirtualHost>

<VirtualHost 1.1.1.2>
Servername host2.dan.com # one of the non-shared IP's listenin on 80
</VirtualHost>

<VirtualHost 1.1.1.1:9999>
ServerName host3.dan.com # This server will listen on port 9999
</VirtualHost>

<VirtualHost 1.1.1.4>
Port 10001 #this server will listen on port 10001
ServerName host4.dan.com
</VirtualHost>

So thats a couple examples.. As you can see you can tell a server -
especially a virtual host - to listen on many different ports in a
number of different ways.

Disclaimer: I'm skipping a lot of shit here and only discussing things
relavent to this dicussion :)

It could get a lot more in depth than that of course or it could get a
lot simpler than that - and *that* is the power of Apache.

Maybe you're not even reading this far down, but I hope that cleared
some things up for ya.. If you have more questions or want to know
something I mentioned in more depth, plase ask :) As you can tell, I
like talking about this kinda shit :)

Sorry to the digest people for making this roughly its own digest ;)

.djc.

Terry Fowler wrote:


 > So, both Listen *and* BindAddress are commented out,
 >
 > but both http://localhost/ and http://127.0.0.1/ work.
 >
 > Is there something to be gained by doing this another
 >
 > way?






More information about the thelist mailing list