Difference between revisions of "Easy Virtual Hosting"
Jump to navigation
Jump to search
(imported from WiKit id 1414) |
(No difference)
|
Latest revision as of 21:07, 3 April 2005
So having played around with virtual hosting for a while I felt that I needed something that would make it easier to add domains. Thus allowing anyone in my team to make a simple change in a txt file, and not have to change any configurations.
So I came up with a little virtualhosting.tcl file The layout is as follows, customize paths as you see fit.
/data/servers/nsshutdown/conf/nsd.tcl (main nsd config)
/data/servers/nsshutdown/conf/virtualhosting.tcl (hosting code)
/data/servers/vhosts/conf/domains/<domain.com> (host names)
/data/servers/vhosts/<domain.com>/<cname>/
logs/
pages/
tcl/
To begin with in the top of nsd.tcl source in the virtualhosting.tcl and register the domains.
nsd.tcl
source /data/servers/nsshutdown/conf/virtualhosts.tcl admin.registerDomains <domain.com> <domains root>
# The hostname and address should be set to actual values. set hostname nsshutdown.com set address ns_info address
----- rest of normal nsd config here.
<domain.com> should be the name of the top level domain your hosting <domains root> should be the path for the domains server roots /data/servers/vhosts/<domains root>/<page root> The cnames are defined in /data/servers/vhosts/conf/domains/<domain.com> As lines containing <cname> <page root>
virtualhosting.tcl
proc admin.getDomains {topLevel} {
# admin.getDomains
# args: top level domain
# return: lists of cname and page root
#
# get all c-class domains for a top level domain
# format of file <cname (without domain)> <page root>
set fh open /data/servers/vhosts/conf/domains/$topLevel r
set hosts read -nonewline $fh
close $fh
return split $hosts
}
proc admin.registerDomains {topLevel base} {
# admin.registerDomains
# args: top level domain, domain base dir containing domain config files
# return: null
# register all sub domains for a top level domain
set directoryfile index.adp,index.html,index.htm,index.xhtml,index.xht,index.php
set basedir /data/servers/vhosts/$base
set domains admin.getDomains $topLevel
set bindir [[file dirname [ns_info nsd]]]
foreach {host hostname} $domains {
# set up page root and directory files
ns_section "ns/server/${host}"
ns_param pageroot ${basedir}/${host}/pages
ns_param directoryfile $directoryfile
ns_param enabletclpages false
# register server name
ns_section "ns/servers"
ns_param $host "${hostname}.${topLevel}"
# configure nssock to go to registered server
ns_section "ns/module/nssock/servers"
ns_param $host "${hostname}.${topLevel}"
ns_param $host "${hostname}.${topLevel}:80"
# configure adp pages
ns_section "ns/server/${host}/adp"
ns_param map "/*.adp"
ns_param enableexpire false
ns_param enabledebug false
# set up modules for server type
# be carefull several modules are not reusable across
# virtual servers, such as lib php.!
ns_section "ns/server/${host}/modules"
ns_param nslog ${bindir}/nslog.so
# configure seperate access logs for each server
ns_section "ns/server/${host}/module/nslog"
ns_param rolllog true
ns_param rollonsignal true
ns_param rollhour 0
ns_param maxbackup 5
ns_param logreqtime true
ns_param file ${basedir}/${host}/logs/access.log
# configure tcl for server
ns_section "ns/server/$host/tcl"
ns_param autoclose true
ns_param debug false
ns_param nsvbuckets 8
ns_param statlevel 0
ns_param statbuff 100
ns_param library ${basedir}/${host}/tcl
}
}
Example usage
Create a server for made-up.com, and cname of here.made-up.com
Take the regular nsd.tcl and just set your server names and ports correctly. Should be a simple change as below
- nsd.tcl
set httpport 80 set httpsport 443
# The hostname and address should be set to actual values.
set hostname made-up.com set address ns_info address
set servername "made-up" set serverdesc "made-up"
# added virtual server config source /data/servers/made-up/conf/virtualhosts.tcl admin.registerDomains made-up.com made-up
# rest is normal nsd.tcl or sample-config.tcl that comes with # aolserver
Set up here.made-up.com
mkdir -p /data/servers/vhosts/conf/domains/ mkdir -p /data/servers/vhosts/made-up/ mkdir -p /data/servers/vhosts/made-up/here/pages mkdir -p /data/servers/vhosts/made-up/here/logs mkdir -p /data/servers/vhosts/made-up/here/tcl
echo "here here" >>/data/servers/vhosts/domains/made-up.com
Start up aolsever and hit here.made-up.com