事例学习开发WEBSERVER服务器(一)

来源:互联网 发布:python tf idf 编辑:程序博客网 时间:2024/05/16 11:10

我想有很多朋友和我一样,想要了解APACHE NGINX的工作原理,最终能独立写一个服务器。我对C语言开发几乎一窍不通,看了网上的很多文章,都是先讲SOCKET编程等等几百页之后,才能讲到这里,学习起来很痛苦,经常思考是否可以另外一种方式,倒叙的方式让其他的人学习起来不那么痛苦。好吧废话少说,咱们开始吧~

今天要做的工作目标:配置环境,浏览源代码。

一、下载WEBSERVER程序(下载)

二、安装。make

三、启动服务器端服务。./shttpd

[root@sysadmin webserver]# ./shttpd sHTTPD ListenPort: 8062       MaxClient: 4       DocumentRoot: /usr/local/var/www/       DefaultFile:index.html       CGIRoot:        DefaultFile:index.html       TimeOut:3       ConfigFile:/etc/sHTTPd.conf==>Worker_ScheduleRun==>Worker_Init==>Worker_Add==>worker<==Worker_Add==>Worker_Add==>worker<==Worker_Add<==Worker_Init

四、测试。curl '127.0.0.1:8062/index.html'

[root@sysadmin study]# curl '127.0.0.1:8062/index.html'test

 

五、SERVER显示

client commingDo task==>do_workselect retval:1Read 166 bytes,'GET /index.html HTTP/1.1User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5Host: 127.0.0.1:8062Accept: */*'==>Request_Parse==>Request_HeaderParse<==Request_HeaderParseURI:'/index.html',patch:'/usr/local/var/www///index.html'<==Request_Parse==>Request_Handle==>Method_Do==>Method_DoGet==>Mine_Typeuri:/index.html,len:11,ext is htmlfound it, ext is html<==Mine_Typen:-1content length:5, status:206<==Method_DoGet<==Method_Doecho header:HTTP/1.1 206 Partial ContentDate: Thu, 04 Apr 2013 13:45:15 GMTLast-Modified: Mon, 01 Apr 2013 21:08:47 GMTEtag: "515986df.5"Content-Type: text/htmlContent-Length: 5Accept-Ranges: bytesContent-Range: bytes 0-4/5, write to client 229 bytes, status:206response len:16384, content length:5read 5 bytes,write 5 bytes<==Request_Handleselect retval:1Read 0 bytes,''<==do_work

六、先到这里!剩下的就是有空的时候看看程序,体会一下结果是什么出来的。


<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击