本文主要基於支持perl的web服務器的選擇。html
一直基於web開發,服務器都是linux下使用webmin搭建的,慚愧的說一句,這麼多年,也好好研究過WEB服務器,單從這個角度,是否是能夠反應出webmin架構和俺們產品的build作得還算OK呢,纔可讓你們夥將更多的精力集中,自身產品的業務上,而不用每一個人都更多花大量時間在一些早已成熟的技術上,若是每一個產品都以這個思想來作,那麼這個社會將有更少的重複勞動,和更高效的產出,扯遠了,回來繼續關於Windows下搭建web服務器。linux
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.web
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.apache
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.windows
2000後再也不維護和使用,使用方法參考文檔較少,初測發現windows下使用,服務常常會中止。不推薦使用。瀏覽器
install web server:https://www.gossland.com/perlcourse/default/install_pws.html服務器
perlwebserver by 2000 year:http://perlwebserver.sourceforge.net/架構
下載Abyss Web Server X1免費版本後,嘗試安裝,報錯,沒法安裝成功,看來免費版本錯誤處理及冗錯作得不是太好,未作更多嘗試。ide
aprelium:http://www.aprelium.com/post
現在主流的Web服務器軟件主要由IIS或Apache組成。IIS支持ASP且只能運行在Windows平臺下,Apache支持PHP,CGI,JSP且可運行於多種平臺,雖然Apache是世界使用排名第一的Web服務器平臺,可是衆所周知,Windows以易用而出名,也所以佔據很多的服務器市場。本專題咱們把Web服務器劃分爲Windows平臺和Linux平臺(包括各類Unix)。
簡易過程
一、安裝apache WEB服務器
二、運行第一個apache WEB頁面
開啓服務,管理->服務,運行apache。
服務開啓後,經過瀏覽器訪問127.0.0.1,apache服務器會默認去安裝目錄的htdocs目錄下打開默認已存在的index.html。
三、安裝perl解釋器
四、配置apache容許打開CGI頁面
配置文件目錄,安裝目錄下的conf目錄,修改httpd.conf文件,DirectoryIndex index.html index.cgi(加入index.cgi)
五、運行第一個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>";
六、使用模版方式,將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模板使用: