我想有很多朋友和我一样,想要了解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 comming Do task ==>do_work select retval:1 Read 166 bytes,'GET /index.html HTTP/1.1 User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5 Host: 127.0.0.1:8062 Accept: */* ' ==>Request_Parse ==>Request_HeaderParse <==Request_HeaderParse URI:'/index.html',patch:'/usr/local/var/www///index.html' <==Request_Parse ==>Request_Handle ==>Method_Do ==>Method_DoGet ==>Mine_Type uri:/index.html,len:11,ext is html found it, ext is html <==Mine_Type n:-1 content length:5, status:206 <==Method_DoGet <==Method_Do echo header:HTTP/1.1 206 Partial Content Date: Thu, 04 Apr 2013 13:45:15 GMT Last-Modified: Mon, 01 Apr 2013 21:08:47 GMT Etag: "515986df.5" Content-Type: text/html Content-Length: 5 Accept-Ranges: bytes Content-Range: bytes 0-4/5 , write to client 229 bytes, status:206 response len:16384, content length:5 read 5 bytes,write 5 bytes <==Request_Handle select retval:1 Read 0 bytes,'' <==do_work
六、先到这里!剩下的就是有空的时候看看程序,体会一下结果是什么出来的。