抛弃IIS --- 小巧的ASP web server ---- netbox

Posted on 2007-12-28 22:22 傅晓风 阅读(1808) 评论(0)  编辑  收藏 所属分类: Web Server

netbox = 网络盒子 是一个很好用而且又小巧的web软件,本篇文章要说的是如何让 netbox 支持多个站点。进入正题:

右击"main.box"用记事本打开,可以看到的是类似如下代码:
而以下默认代码只支持一个站点使用,如何多个站点同用"netbox"呢?
请关注本篇文章
---------------------------------------------------------------
单个站点使用的代码:
--------------------------------
Dim httpd
Shell.Service.icon = "\status\on.gif"
Shell.Service.RunService "ASPWebserver", "AspWeb服务器", "AspWeb服务器 off"

'---------------------- 服务事件开始 ---------------------

Sub OnServiceStart()
Shell.Service.SetTimer 100
Set httpd = CreateObject("netbox.HttpServer")

If httpd.Create("",80) = 0 Then
Set host = httpd.AddHost("", "\web\")
host.EnableWrite=false
host.Enables cript = true
host.AddDefault "default.asp"
host.AddDefault "default.htm"
host.AddDefault "default.html"
host.AddDefault "index.htm"
host.AddDefault "index.asp"
host.AddDefault "index.html"

httpd.Start
else
Shell.MsgBox "服务器启动失败,80端口可能被占用!请停止当前WEB服务器或用记事本打开main.box文件修改端口.","错误对话框"
Shell.Quit 0
end if
End Sub

Sub OnServiceStop()
httpd.Close
End Sub

Sub OnServicePause()
Shell.Service.Icon = "\status\off.gif"
Shell.MsgBox "服务器暂停运行!必要时记得打开噢!","暂停运行"
End Sub

Sub OnServiceResume()
OnServiceTimer
httpd.Start
End Sub

Sub OnServiceTimer
If Shell.Service.icon = "\status\on.gif" Then
   Shell.Service.icon = "\status\on1.gif"
Else
   Shell.Service.icon = "\status\on.gif"
End If
End Sub
--------------------------------------------------------------------------------
两个站点使用的代码:
--------------------------------
Dim httpd1,httpd2
Dim httpd
Shell.Service.RunService "ASPWebserver", "AspWeb服务器", "AspWeb服务器 off"
'---------------------- 服务事件开始 ---------------------
Sub OnServiceStart()
Set httpd1 = NetBox.CreateObject("NetBox.HttpServer")
Set httpd2 = NetBox.CreateObject("NetBox.HttpServer")
If httpd1.Create("", 80) = 0 Then
Set host1 = httpd1.AddHost("127.0.0.1", "\web\")
host1.Enables cript = true
host1.AddDefault "default.asp"
host1.AddDefault "default.htm"
host1.AddDefault "index.asp"
host1.AddDefault "index.htm"
'httpd.Start
else
Shell.Quit 0
end if
'Set httpd = NetBox.CreateObject("NetBox.HttpServer")
If httpd2.Create("", 81) = 0 Then
Set host2 = httpd2.AddHost("127.0.0.2", "\web\")
host2.Enables cript = true
host2.AddDefault "default.asp"
host2.AddDefault "default.htm"
host2.AddDefault "index.asp"
host2.AddDefault "index.htm"
httpd1.Start
httpd2.start
else
Shell.Quit 0
end if
End Sub
Sub OnServiceStop()
httpd1.Close
httpd2.Close
End Sub
Sub OnServicePause()
httpd1.Stop
httpd2.Stop
End Sub
Sub OnServiceResume()
httpd1.Start
httpd2.Start
End Sub

---------------------------------------------------------------------------------
三个站点同时使用:
--------------------------------
Dim httpd1,httpd2,httpd3
Dim httpd
Shell.Service.RunService "ASPWebserver", "AspWeb服务器", "AspWeb服务器 off"
'---------------------- 服务事件开始 ---------------------
Sub OnServiceStart()
Set httpd1 = NetBox.CreateObject("NetBox.HttpServer")
Set httpd2 = NetBox.CreateObject("NetBox.HttpServer")
Set httpd3 = NetBox.CreateObject("NetBox.HttpServer")
If httpd1.Create("", 80) = 0 Then
Set host1 = httpd1.AddHost("127.0.0.1", "\web\")
host1.Enables cript = true
host1.AddDefault "default.asp"
host1.AddDefault "default.htm"
host1.AddDefault "default.html"
host1.AddDefault "index.htm"
host1.AddDefault "index.asp"
host1.AddDefault "index.html"
'httpd.Start
else
Shell.Quit 0
end if
'Set httpd = NetBox.CreateObject("NetBox.HttpServer")
If httpd2.Create("", 81) = 0 Then
Set host2 = httpd2.AddHost("127.0.0.2", "\web\")
host2.Enables cript = true
host2.AddDefault "default.asp"
host2.AddDefault "default.htm"
host2.AddDefault "default.html"
host2.AddDefault "index.htm"
host2.AddDefault "index.asp"
host2.AddDefault "index.html"
'httpd.Start
else
Shell.Quit 0
end if
'Set httpd = NetBox.CreateObject("NetBox.HttpServer")
If httpd3.Create("", 82) = 0 Then
Set host3 = httpd3.AddHost("127.0.0.3", "\web\")
host3.Enables cript = true
host3.AddDefault "default.asp"
host3.AddDefault "default.htm"
host3.AddDefault "default.html"
host3.AddDefault "index.htm"
host3.AddDefault "index.asp"
host3.AddDefault "index.html"
httpd1.Start
httpd2.start
httpd3.start
else
Shell.Quit 0
end if
End Sub
Sub OnServiceStop()
httpd1.Close
httpd2.Close
httpd3.Close
End Sub
Sub OnServicePause()
httpd1.Stop
httpd2.Stop
httpd3.Stop
End Sub
Sub OnServiceResume()
httpd1.Start
httpd2.Start
httpd3.Start
End Sub

----------------------------------------------------------------
以此内推,相信大家对照一下就能看明白!
当中IP请自行更改,多个站点,若用的是花生壳,请改为花生壳域名。
每处IP填写不同域名!!

最后在IE的访问地址如下:

(例)

                域名                 端口

站点一:127.0.0.1            80                   最后IE中要输入的地址:127.0.0.1

站点二:127.0.0.2            81                   最后IE中要输入的地址:127.0.0.2:81

站点三:127.0.0.3            82                   最后IE中要输入的地址:127.0.0.3:82

除了设了80端口的站点,用域名访问时不需要加所设端口外,其它的都要加端口。

 

大家复制以下代码,自已修改,或者下载本文章带的完整附件,然后进得更改.

-------------------------------------------------------------------------------------------

Dim httpd,host(10),i                          '有没看到我这边写着10,因为我下边网站列表里最后是10

                                                         '也就是说我在下边再添一个网站,那下边就多条11的,上边也要改成11
Shell.Service.RunService "allyes", "同端口同时运行多站点的", "同端口同时运行多站点"
'---------------------- Service Event ---------------------
Sub OnServiceStart()
Set httpd = CreateObject("NetBox.HttpServer")

If httpd.Create("", 80) = 0 Then                                                    '这是端口,这里默认为80
Set host(0) = httpd.AddHost("192.168.0.1", "\001\")                     '这些是网站,现在总共列有11条,就是说,
Set host(1) = httpd.AddHost("192.168.0.2", "\002\")                     '我当前运行了11个站点,输入域名就访问
Set host(2) = httpd.AddHost("192.168.0.3", "\003\")                     '该处设置的目录里.
Set host(3) = httpd.AddHost("192.168.0.4", "\004\")                     '为了方便,我写的是ip,大家自已改为域名
Set host(4) = httpd.AddHost("192.168.0.5", "\005\")                     '每个域名都不一样,一个就代表一个站
Set host(5) = httpd.AddHost("192.168.0.6", "\006\")                     '001..002..003 这些是 网站所在目录
Set host(6) = httpd.AddHost("192.168.0.7", "\007\")                     'set host(0)....set host(10) 这里大家认真
Set host(7) = httpd.AddHost("192.168.0.8", "\008\")                     '看下就会明白,有几个站点就写到几了
Set host(8) = httpd.AddHost("192.168.0.9", "\009\")                     '注:从0开始算一个
Set host(9) = httpd.AddHost("192.168.0.10", "\010\")
Set host(10) = httpd.AddHost("192.168.0.11", "\011\")
For i=0 to Ubound(host)
host(i).EnableScript = true                                                          '以下是网页访问顺序,请自行设置修改
host(i).AddDefault "default.asp"
host(i).AddDefault "default.htm"
host(i).AddDefault "default.html"
host(i).AddDefault "index.asp"
host(i).AddDefault "index.htm"
host(i).AddDefault "index.html"
Next
httpd.Start
Else
Shell.Quit 0
End If
End Sub
Sub OnServiceStop()
            httpd.Close
End Sub
Sub OnServicePause()
            httpd.Stop
End Sub
Sub OnServiceResume()
            httpd.Start
End Sub


只有注册用户登录后才能发表评论。


网站导航: