http:

      

       http协议:

              http/0.9:原型版本;

              http/1.0:cache, MIME(multipupose internet Mail Extensions)

                     method:GET、POST、HEAD、PUT、DELETE、TRACE、OPTIONS、...             

              http/1.1:缓存功能大大增强

                     speedy:spdy

              http/2.0

                                  

              80/tcp

             

       https协议:

              443/tcp

             

       IANA:

              0-1023:众所周知的,永久地分配给固定的应用使用;特权端口(仅root可用);

              1024-41951:注册端口,但要求不是特别严格,分配给程序注册为某应用使用;

              41952+:客户端程序使用的随机端口,动态端口,或称为私有端口;/proc/sys/net/ipv4/ip_local_port_range;

             

       BSD Socket:IPC一种实现,允许位于不同主机之上的进程之间互相通信的解决方案之一;

              Socket API:

                     SOCK_STREAM:tcp套接字;

                     SOCK_DGRAM:udp套接字;

                     SOCK_RAW:裸套接字;

                    

              根据套按使用的地址格式:

                     AF_INET:ipv4地址家族;

                     AF_INET6:ipv6

                     AF_UNIX:Unix_sock;

                    

              TCP Finite State Machine:

              TCP协议的特性:

                     建立连接:三次握手;

                     将数据打包成段:校验和(CRC32)

                     确认、重传及超时;

                     排序:逻辑序号;

                     流量控制:滑动窗口;

                     拥塞控制:慢启动及拥塞避免算法;

http:hyper text tranfer protocol, 超文本传输协议;

Html: hyper text mark language,超文本标记语言;

工作模式:request/response

                     一次完整的http事务:请求<-->响应;

                    

                     web资源:

                            一个html文档;

                            一个图片;

                            一个mp3文件片断;

                            ...

                           

                            URL:资源标识,用于描述服务器上某特定资源的位置;

                                   Uniform Resource Locator

                                          scheme://Server[:port]/PATH/TO/SOME_RESOURCE

                                         

                            资源的种类:

                                   静态资源:.jpg, .gif, .png, .html, .txt,  直接请求相应 不需要运算

                                   动态资源:需要在服务器或客户端运行后返回结果

                                          服务器端技术:.php, .jsp, ...

                                          客户端技术:.js

                           

              一次完整的http请求的处理过程:

                     (1) 建立或处理连接:接收请求或拒绝请求;

                     (2) 接收请求:接收客户端发来的具体请求报文;

                     (3) 处理请求:对请求报文进行解析;

                     (4) 访问资源:通过存储IO获取用户请求的资源;

                     (5) 构建响应报文:

                     (6) 发送响应报文 :

                     (7) 记录于日志中:

             

              并发响应模型:

                     单进程I/O模型:串行响应;

                     多进程I/O模型:同时启动多个进程,每个进程响应一个请求;

                     复用的I/O模型:一个进程响应多个请求;

                            多线程模型:一个进程生成多个线程,每个线程响应一个请求;

                            事件驱动:一个进程直接响应多个请求;

                     复用的多进程I/O结构:启动m个进程,每个进程生成n个线程,每个线程响应一个请求;

资源映射:

                     chroot:

                            /var/test/a/b/index.html

                           

                            chroot /var/test,

                                   /a/b/index.html

                    

                            例如:/var/www/html/

                                          p_w_picpaths/logo.jpg

                                   http://www.magedu.com:80/p_w_picpaths/log.jpg

                                  

                            DocumentRoot  页面资源存放的路径

                           

                            web服务器的资源映射机制:

                                   (a) DocumentRoot

                                   (b) alias

                                   (c) 虚拟主机的docroot

                                   (d) 用户的docroot

                                   ...

       http请求处理中的连接方式:

                     保持连接:长连接,keepalive 当客户端请求每一个资源时都会建立一次tcp链接 每次一链接请求一个资源,大量资源都用在握手上,效率低下,保持链接则可以基于一次握手传送多个资源

                     非保持连接:短连接,  不保持链接 每一个资源单独握手

折中思路:防止长连接占用而不请求资源

                     时间:时间限制

                     数量:数量限制 

                    

       http协议的实现:

              简单的基本http协议服务器:

                     httpd (apache)

                     nginx

                     lighttpd

                    

              application server:动态服务器技术;

                     iis, tomcat, jetty, resin, ...

                     weblogic, websphere, jboss, glassfish, ...

                    

              httpd:

                     www.netcraft.com  数据挖掘网站

                     ASF:apache software foundation

                     apache,a patchy server, httpd

                    

              httpd的特性:

                     高度模块化:core + modules

                     DSO: Dynamic shared objects

                            支持动态装载和卸载;

                     MPM:multipath processing modules 多路处理模块 (httpd 2.2以前的版本不支持DSO机制)

                            prefork:一个主进程,多个子进程;一个进程响应一个请求;

                                   主进程:管理子进程;创建套接字;接收用户请求,并派发给某子进程处理;...

                                   子进程:处理请求、响应请求;

                            worker:多进程多线程模型;一个线程响应一个请求;

                                   主进程:管理子进程;创建套接字;接收用户请求,并派发给某子进程处理;...

                                   子进程:负责管理线程;

                                   线程:处理并响应请求;

                            event:事件驱动模型,多进程模型,每个进程响应多个请求;

                                   主进程:管理子进程;创建套接字;接收用户请求,并派发给某子进程处理;...

                                   子进程:处理并响应请求;

                                  

                                   httpd-2.2:event为测试模型;

                                          CentOS 6:MPM不支持DSO机制;

                                   httpd-2.4:production ready;支持DSO机制;

                                          CentOS 7:

***************************************

httpd的功能特性:

CGI:common gateway interface;

虚拟主机:IP, PORT, HOSTNAME

反向代理

负载均衡:bytraffic, bybusiness, byrequest

路径别名

丰富的用户认证机制

       basic:

       digest:

支持第三方模块

...

*******************************************

CentOS 6:httpd-2.2

sysinit脚本:/etc/rc.d/init.d/httpd

程序环境:

       配置文件:

              /etc/httpd/conf/httpd.conf

              /etc/httpd/conf.d/*.conf

       程序文件:

              /usr/sbin/httpd

              /usr/sbin/httpd.event

              /usr/sbin/httpd.worker

                                  

              脚本配置文件:/etc/sysconfig/httpd

       日志文件:

              /var/log/httpd

                     access_log:访问日志

                     error_log:错误日志

       站点文档根目录:

              /var/www/html

       模块文件路径:

              /usr/lib64/httpd/modules             

chkconfig httpd on|off

                           

CentOS 7:httpd-2.4

Systemd Unit File:/usr/lib/systemd/system/httpd.service

                    

程序环境:

       配置文件:

              /etc/httpd/conf/httpd.conf

              /etc/httpd/conf.modules.d/*.conf

              /etc/httpd/conf.d/*.conf

       程序文件:

              /usr/sbin/httpd

 

              MPM支持DSO机制,所以各为一个独立的模块;

                                  

       日志文件:

              /var/log/httpd

                     access_log:访问日志

                     error_log:错误日志

       站点文档根目录:

              /var/www/html

       模块文件路径:

              /usr/lib64/httpd/modules      

                                  

systemctl enable httpd.service