Windows下WEB服务器的选择与搭建

时间:2023-03-09 06:02:38
Windows下WEB服务器的选择与搭建

  本文主要基于支持perl的web服务器的选择。

  一直基于web开发,服务器都是linux下使用webmin搭建的,惭愧的说一句,这么多年,也好好研究过WEB服务器,单从这个角度,是不是可以反应出webmin架构和俺们产品的build做得还算OK呢,才可以让大家伙将更多的精力集中,自身产品的业务上,而不用每个人都更多花大量时间在一些早已成熟的技术上,如果每个产品都以这个思想来做,那么这个社会将有更少的重复劳动,和更高效的产出,扯远了,回来继续关于Windows下搭建web服务器。

  A long time ago, Windows included a simple program called Personal Web Server (PWS) which provided an easy little webserver to use with Perl. With the release of Windows ME and XP, PWS was discontinued and replaced with Internet Information Server, known as IIS. Last time I tried, which I freely admit was quite a while ago now, configuring IIS for use with Perl was not that easy. There are simpler ways of doing it.

  If you just want a simple webserver to test with, I recommend a different webserver than IIS. This webserver is free, and is well documented. You can find it at Aprelium. Look for the Abyss Web Server X1. It works very well and is much easier to set up than IIS. The exact configuration details are spelled out in the documentation for the X1 server so I won't repeat them here. But I think you'll find it is pretty easy to install and set up.

  If you want something more configurable and powerful, you can't go wrong with the Apache webserver, which is available for Windows just as readily as for Linux. Again, the exact configuration details are not provided here, since there is Apache documentation for this. However, if enough users ask for explicit instructions to be included here, start asking by email, and I'll add them in.

1       PWS(perlwerbserver)

2000后不再维护和使用,使用方法参考文档较少,初测发现windows下使用,服务经常会停止。不推荐使用。

install web server:https://www.gossland.com/perlcourse/default/install_pws.html

perlwebserver by 2000 year:http://perlwebserver.sourceforge.net/

2       Aprelium

下载Abyss Web Server X1免费版本后,尝试安装,报错,无法安装成功,看来免费版本错误处理及冗错做得不是太好,未做更多尝试。

aprelium:http://www.aprelium.com/

3       基于apache的WEB服务器

如今主流的Web服务器软件主要由IIS或Apache组成。IIS支持ASP且只能运行在Windows平台下,Apache支持PHP,CGI,JSP且可运行于多种平台,虽然Apache是世界使用排名第一的Web服务器平台,但是众所周知,Windows以易用而出名,也因此占据不少的服务器市场。本专题我们把Web服务器划分为Windows平台和Linux平台(包括各种Unix)。

简易过程

  1、安装apache WEB服务器

  2、运行第一个apache WEB页面

     开启服务,管理->服务,运行apache。

    服务开启后,通过浏览器访问127.0.0.1,apache服务器会默认去安装目录的htdocs目录下打开默认已存在的index.html。

  3、安装perl解释器

  4、配置apache允许打开CGI页面

    配置文件目录,安装目录下的conf目录,修改httpd.conf文件,DirectoryIndex index.html index.cgi(加入index.cgi)

  5、运行第一个cgi页面

    将程序放到apache安装目录的cgi-bin目录下,通过web访问http://127.0.0.1/cgi-bin/index.cgi即可。

index.cgi:

#!c:/perl/bin/perl(perl的安装目录)

use CGI qw(:standard);

use strict;

print header;

print "<B>it works ! hello world</B>";

  6、使用模版方式,将html从CGI中分离

index.cgi:

#!c:/perl/bin/perl

use strict;

print "Content-type: text/html\n\n";

print &Template("../htdocs/index.html");

sub Template

{

  my $file;

  my $HTML;

  $file = $_[] || die "Template: No template file specified.\n";

  open (FILE,"<$file") || die "Template: Couldn't open $file:$!\n";

  while (<FILE>) { $HTML .= $_; }

  close(FILE);

  #下面两个语句实现的功能相同

  $HTML =~ s/(\$\w+)/eval "$1"/ge;

  #$HTML =~ s/\$(\w+)/${$1}/g;

  return $HTML;

}

参考文献

WEB服务器搭建:

http://school.cfan.com.cn/zhuanti/webserver/

apache WEB服务器搭建:

http://carywu.blog.51cto.com/13185/9551

基于apache的perl实现动态页面:

http://www.oschina.net/question/17_71

CGI配合HTML模板使用:

http://www.linuxfly.org/post/335/