01.Nginx basic principle Http

1.Http Protocol Overview

HTTPThe full name of HyperText Transfer Protocolthe Chinese called Hypertext Transfer Protocol

1. What is hypertext?

It has hyperlinks (Link) and a variety of multimedia elements marked text. These hypertext documents linked to each other to form a network (Web), is also known as web page (Web Page). Use these links URLrepresent. The most common hypertext format HTML HTML.

html file -> contains a variety of elements (URL link) -> short form web page web page.

2. what is URL, URL referred to as Uniform Resource Locator. It is part of the URL by the protocol, the domain name: port, path and file name

3. That Hypertext Transfer httpWhat protocol is?
Is a followURLinstructions, the hypertext document transfer from one host (Web server) to another host (browser) application layer protocol, in order to achieve a hyperlink function.

 

 

2.Http works

3.Http protocol version

http1.0 protocol using a short connection: the establishment of a tcp connection, launch a http request, end, tcp open.
http1.1 protocol using a long connection: the establishment of a tcp connection, initiate http request many times, ending, tcp port.

3.Http request response

1. httpRequest message method

get     # 获得请求文件信息的数据内容(下载)
post    # 用户提交数据至服务器端存储(上传)

Request URL:http://10.0.0.7/index.html # 请求的URL Request Method:GET # 请求的方法 Status Code:200 OK # 当前的状态 Remote Address:10.0.0.7:80 # 远程的主机 

2. The httpreturn a status code (Status-Code), a 3-digit

200     # 成功请求
301     # 永久重定向(redirect) 
302 # 临时重定向(redirect) 304 # 浏览器缓存 403 # 请求不到首页或权限被拒绝 404 # 请求的资源不存在 500 # 服务器内部错误,程序代码错误 502 # 找不到后端的资源 504 # 请求超时 

3. Users access the site carries parameters and the parameters returned from the server

#1.概况
Request URL: http://10.0.0.7/index.html         # 请求的URL地址
Request Method: GET                             # 请求的方法(获取) Status Code: 304 Not Modified # 返回的状态 Remote Address: 10.0.0.7:80 # 请求的地址 #2.客户端请求的头部信息 Accept: text/html, # 请求的类型 Accept-Encoding: gzip, deflate # 是否进行压缩 Accept-Language: zh-CN,zh;q=0.9 # 请求的语言 Cache-Control: max-age=0 # 缓存 Connection: keep-alive # TCP长连接 Host: www.baidu.com # 请求的域名 If-Modified-Since: Fri, 04 May 2018 08:13:44 GMT# 修改的时间 User-Agent: Mozilla/5.0 # 请求浏览器的工具 "=== 请求一个空行 ===" "=== 请求内容主体 ===" #3.服务端响应的头部信息 HTTP/1.1 304 Not Modified # 返回服务器的http协议,状态码 Date: Fri, 14 Sep 2018 09:14:28 GMT # 返回服务器的时间 Server: Apache/2.4.6 (CentOS) PHP/5.4.16 # 返回服务器使用的软件(Apache php) Connection: Keep-Alive # TCP长连接 Keep-Alive: timeout=5, max=100 # 长连接的超时时间 "=== 返回一个空行 ===" "=== 返回内容主体 ===" 

4.Http related terms pv、ip、uv assume that the company has a building, Building 100 people, everyone has a computer and a cell phone, the Internet is through nat conversion exit, everyone click the site twice, what corresponds to pv,uv,iphow much each

PV:页面浏览量, 400
uv:独立的客户, 200
ip:独立IP, 1个

6.Http访问流程

1.http协议原理总结

1.用户输入域名->浏览器跳转->浏览器缓存->Hosts文件->DNS解析( 递归查询 | 迭代查询 )
    客户端向服务端发起查询->递归查询
    服务端向服务端发起查询->迭代查询
2.由浏览器向服务端发起TCP连接(三次握手)
    客户端  -->请求包连接-syn=1 seq=x           服务端
    服务端  -->向应客户端syn=1 ack=x+1 seq=y 客户端 客户端 -->建立连接 ack=y+1 seq=x+1 服务端 3.客户端发起http请求: 1.请求的方法是什么: Get 获取 2.请求的Host主机是: www.baidu.com 3.请求的资源是什么: /index.html 4.请求的端口是什么: 默认http是80 https 443 5.请求携带的参数是: 属性(请求的类型、压缩、认证、浏览器信息、等等) 6.请求最后的空行 4.服务端响应的内容是 1.服务端响应使用的WEB服务软件 2.服务端响应请求文件的类型 3.服务端响应请求的文件是否进行压缩 4.服务端响应请求的主机是否进行长连接 5.客户端向服务端发起TCP断开(四次挥手) 客户端 --> 断开请求 fin=1 seq=x --> 服务端 服务端 --> 响应断开 fin=1 ack=x+1 seq=y --> 客户端 服务端 --> 断开连接 fin=1 ack=x+1 seq=z --> 客户端 客户端 --> 确认断开 fin=1 ack=z+1 seq=sj --> 服务端 

2.用户访问网站集群架构流程

1.客户端发起http请求,请求会先抵达前端的防火墙
2.防火墙识别用户身份,正常的请求通过内部交换机通过tcp连接后端的负载均衡,传递用户的http请求
3.负载接收到请求,会根据请求的内容进行下发任务,通过tcp连接后端的web,转发发用户的http请求
4.web接收到用户的http请求后,会根据用户请求的内容进行解析,解析分为如下:
    静态请求:web直接返回给负载均衡->防火墙->用户
    动态请求:web向后端的动态程序建立TCP连接,将用户的动态http请求传递至动态程序->由动态程序进行解析
5.动态程序在解析的过程中,如果碰到查询数据库请求,则优先与缓存建立tcp连接,并发起数据查询操作。 6.如果缓存没有对应的数据,动态程序再次向数据库建立tcp连接,并发起查询操作。 7.最后数据由, 数据库->动态程序->缓存->web服务->负载均衡->防火墙->用户。

Guess you like

Origin www.cnblogs.com/syf-com/p/11536605.html