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 = $_[0] || 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/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM