Of course V4 has some virtual server capability built into it.
Ah sorry just re-read the wiki page and saw that the V4 stuff is the top
section.

There's no real need to have separate config files for the different virtual
servers and perhaps calling them front-end and backend is confusing in the
V4 situation where you only have one nsd process.

Question:
With V4 how would you go about using nsvhr and nssock/nsunix if you want to
load balance across multiple server processes
and what about when the backend servers are on different machines?



Note:
In V4 as well as being able to serve multiple hostnames from the one IP
address using some small extra modifications to the config file it is
possible to listen to multiple ports on the same IP address as well.


Here's how I use V4's built in vserver support with just the one config
file:

I have some 'global' configuration stuff :

set some useful variables e.g. bindir, serverdir etc.
ns_section  ns/parameters
ns_section  ns/threads
ns_section  ns/charsets
ns_section  ns/encodings
ns_section  ns/mimetypes
ns_section  ns/mimeicons  (optional for my improveed Apache style 'dirindex'
ns_section  ns/db         (I guess in this case all the virtual servers are
sharing the same db pools?
                                        - this means they all use the same db which 
may be useful)


I then setup the virtual server information in an array called 'servers':
The key in the array contains the 'order' in which the servers are started
and the 'name' of the server
The value is a list containing the 'description' of the server and all the
'host' headers to match on.
Note below virtual servers 3 and 4 have the same domainname but different
ports.



############################################################################
###
#
# Set up the servers (virtual hosts)
#
############################################################################
###
set servers(1,com)                      [list "Main site" www.mysite.com]
set servers(2,docs)                     [list "Documentation"
docs.mysite.com]
set servers(3,test)                     [list "Test server" test.mysite.com]
set servers(4,test8080)                 [list "Test server on 8080"
test.mysite.com:8080]


ns_section  ns/servers
foreach server [lsort [array names servers]] {
    set serverdesc [lindex $servers($server) 0]
    set servername [string range $server [expr [string first , $server] + 1]
end]
    ns_log notice "Adding server '$serverdesc'"
    ns_param    $servername             $serverdesc
}
############################################################################
###



I then setup nssock (globally) and configure its tuning parameters etc.
Do the same for nsssl as well if you are using this - is this the same for
nsopenssl?)



############################################################################
###
#
# Socket driver module (HTTP)  -- nssock (driver.c)
#
############################################################################
###
ns_section  ns/modules
ns_param    nssock                      ${bindir}/nssock${ext}
#
ns_section  ns/module/nssock
ns_param    hostname                    $hostname
;# This is not the same as your hostname
ns_param    address                     $address
;# This is not the same as your host addr
...
# other nssock tuning parameters
...



I then tell nssock about the virtual servers defined above:


ns_section  ns/module/nssock/servers
foreach server [lsort [array names servers]] {
    set serverdesc [lindex $servers($server) 0]
    set servername [string range $server [expr [string first , $server] + 1]
end]
    foreach vhost [lrange $servers($server) 1 end] {
        ns_log notice "Adding virtual server $vhost to $servername"
        ns_param    $servername         $vhost
    }
}
############################################################################
###


Then I have a foreach loop that goes through each virtual server and sets up
its server specific parameters
This allows the servers to share much of the configuration (meaning you only
need to change it once in one place)
but also allows individual virtual servers to have different settings:


foreach server [lsort [array names servers]] {
    set servername                      [string range $server [expr [string
first , $server] + 1] end]
    set serverroot                      servers/${servername}
    set serverdir                       ${homedir}/servers/${servername}
    set pageroot
${homedir}/servers/${servername}/pages
    foreach d [list log servers $serverroot $serverroot/modules
$serverroot/pages] {
        if ![file exists $homedir/$d] {
                file mkdir $homedir/$d
        }
    }


ns_section  ns/server/${servername}
      Here you can point different virtual servers at the same pageroot and
in the code switch on the 'host' header
        or the sever name to give the pages different brandings.
ns_section  ns/server/${servername}/db
ns_section  ns/server/${servername}/tcl
ns_section  ns/server/${servername}/fastpath
ns_section  ns/server/${servername}/redirects
ns_section  ns/server/${servername}/adp
ns_section  ns/server/${servername}/pools
ns_section  ns/server/${servername}/pool/main
ns_section  ns/server/${servername}/stats
ns_section  ns/server/${servername}/urlstats
ns_section  ns/server/${servername}/module/nscgi
ns_section  ns/interps/CGIinterps
ns_section  ns/environment/CGIenvironment
ns_section  ns/server/${servername}/module/nslog
ns_section  ns/server/${servername}/modules


load a local nssock for each other port you have virtual servers listening
on:
you can switch on the servername at any point in the foreach loop to set
different parameters for a specific virtual server



if {$servername == "test8080"} {
############################################################################
###
ns_section  ns/server/$servername/module/nssock
ns_param        port                                      8080
ns_section  ns/server/${servername}/modules
ns_param    nssock                          ${bindir}/nssock${ext}
############################################################################
####
}


close the foreach loop and load any final global/common stuff

e.g.  not sure if you could have a different nscp for each virtual server -
you'd need to configure each one with a different port I suspect.

ns_section  ns/server/${servername}/module/nscp
ns_section  ns/server/${servername}/module/nscp/users
ns_section  ns/server/${servername}/modules
    ns_param    nscp                        ${bindir}/nscp${ext}
############################################################################
###
ns_log notice "nsd.tcl: finished reading config file."


HTH,

Tim




> -----Original Message-----
> From: AOLserver Discussion
> [mailto:[EMAIL PROTECTED] Behalf
> Of Dossy
> Sent: Saturday, October 25, 2003 2:11 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [AOLSERVER] Virtual Server Information for the Docs
>
>
> On 2003.10.24, derek keller <[EMAIL PROTECTED]> wrote:
> > http://www.panoptic.com/wiki/aolserver/98
> >
> > This is what helped me.
>
> And, of course, if you read that page and something is still unclear,
> make a note on the page and/or send the question to the mailing list.
>
> Thanks,
>
> -- Dossy
>
> --
> Dossy Shiobara                       mail: [EMAIL PROTECTED]
> Panoptic Computer Network             web: http://www.panoptic.com/
>   "He realized the fastest way to change is to laugh at your own
>     folly -- then you can let go and quickly move on." (p. 70)
>
>
> --
> AOLserver - http://www.aolserver.com/
>
> To Remove yourself from this list, simply send an email to
> <[EMAIL PROTECTED]> with the
> body of "SIGNOFF AOLSERVER" in the email message. You can
> leave the Subject: field of your email blank.
>


--
AOLserver - http://www.aolserver.com/

To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of 
your email blank.

Reply via email to