Basic knowledge related to HTTP protocol

Source: Internet
Author: User
Tags web hosting python script

Related content: HTTP concept, version, working mode, Web resource, open source implementation (dynamic, static resource request and response), httpd features, httpd function, httpd program Environment


HTTP protocol:
Hyper-text Transfer Protocol, Hypertext Transfer Protocol;

Html:hyper-text Marked Language, Hyper-text markup language;



Version of http: 0.9,1.0,1.1

0.9: The most original version

Function:

Method:get,put;

1.0:

Function:

Mime:multipurpose Internet Mail Extensions, multi-purpose Internet email extension;
Cache: Caching; CDN
Method:get,put,post,delete,head,trace,connect,options;
Get: Request for the specified resource;
PUT: Uploads the latest version of the resource to the specified location;
POST: Used to implement form authentication, append relevant data after resource;
Delete: The request server deletes the resource that is clearly identified;
Head: As with the Get method, all requests are made to the server for resources, but the head method only asks the server for the header meta-information of the response message;
TRACE: Requests the server to echo received request information, for testing or fault diagnosis;
CONNECT: reserved for future use;
Options: Request the performance of the query server, or query the resource-related options and the methods available to request resources;

1.1:

Function:

Continuation of the function of 1.0, and 1, enhanced the cache function, 2, continuous connection mechanism: KeepAlive, also known as persistent connection, long connection;


Operating mode:

The operating mode of the HTTP protocol: Request/response mode;
A full HTTP transaction: request <--> response;

Client request resource, server response message

A complete HTTP communication, including one request and a response corresponding to the request;

Concurrency Response Model:
Single-Process IO Model: Only one process is used to process and respond to client requests, and only one client, serial response model can be processed and responded to at a time;
Multi-process IO Model: Start multiple processes at the same time, each process can only process and respond to a client request;
Multiplexed IO Model: Each process can process and respond to requests from multiple clients at the same time;
Multi-threaded IO Model: Each process can generate multiple threads, and each thread can respond to a user request;
Event-driven IO model: Each process directly processes and responds to requests from multiple clients, using event notification mechanisms;
multiplexed multi-process IO Model: Start M processes, and each process can generate n threads, each thread can process and respond to a client's request; M*n client;
Multiplexed event-driven IO Model: start m processes, each process is an event-driven way to directly process and respond to requests from multiple clients;


Web Resources (classification, resource request process, resource identifier, resource mapping path)

Classification:

Static resources:
The server responds directly to the client's resources according to the client's request;
HTML Document
Image
Video clips, audio clips
Plain text
Css
...

Dynamic resources:
A program file, usually written in a programming language, that generates a corresponding HTML page after it has been executed in a particular way on the server, and the server responds to the client's resources by running the generated HTML page;

Server-Side Dynamic resources:
PHP script
JSP Program
. NET Program
Python script
Ruby Script
C + + Programs

Client Dynamic resources:
JavaScript scripts
Servlet
Activex


Resource Request Process:

1. Establishing a TCP connection
2. Receive the request: After the message sent by the client is unpacked by the communication subnet, it is placed in the memory space of the corresponding application in the user space;
3. Analysis processing Request: By reading the HTTP protocol header and the body part of the message, the client requests the resources to obtain specific information;
4. Access resources: Load client-requested resources from IO devices such as disks through a specific IO method;
5. Build response messages: encapsulate the loaded resources using a specific protocol;
6. Send the response message:
7. Logging Information:


Resource Identifier:

Url:uniform Resource Locator, Uniform Resource Locator;
A URL is a set of strings in a specific format that is used on the Internet to describe how a Web resource is positioned;
URLs typically have three parts:
1. Agreement: The way in which resources are provided or accessed;
Available protocols: Https,http,ftp,ssh,mailto,gopher, ...
2. Host ID: The FQDN of the host can be used, or the IP address can be used;
3. The path of the resource storage: relative to the host's storage path; a mapping path implemented in a particular way that identifies the specific location of the resource, which is the path from the root and identifies the root, which is the root of the Web service, not the root of the file system;

URL Common standard format:
[scheme://] [Username:[email protected]] server[:p ort][/path/to/resource][? Parameters=value&&amp, ...] [#FLAG]


Resource Mapping Path:

Chroot mechanism:

Such as:
/var/www/html/a.html (path on the root file system)

/var/www/html/---->/(Path of Web services)

documentroot/var/www/html/(Instructions for mapping the Web root directory)

Http://server/a.html

How the Web server's resource path is mapped:
1.DocumentRoot
2.Alias
3.VirtualHost DocumentRoot
4. User's Docroot
...


Open source implementation (dynamic, static resource request and response)

To implement the processing and response of a static resource request:
HTTPD (Apache)
Nginx (Engine X)
Tengine
Lighttpd

Implementation of dynamic resource request processing and response: Application server;
Jsp:
Tomcat
Weblogic
Websphere
Jboss
Glassfish
Php:
Php
php-fpm
Python:
Python
. NET:
Iis


Features of the httpd:

Highly modular: Core + Modules
Dso:dynamic shared object, which dynamically shares objects, enables dynamic loading and unloading of modules;
The modules are divided into two categories:
Static modules: The passive module compiles the source code directly to the module in the core, and if you want to replace the static module, you must change the core file; all only after restarting the service process will it take effect;

Dynamic module: Can be dynamically loaded and unloaded based on the DSO mode, after changing the configuration operation, only need to overload the configuration file to take effect;
Mpm:multipath processing Modules, multi-channel processing module, used to set the concurrency response model of httpd process;
Prefork: Multi-process IO model;
1. A master process, multiple sub-processes;
2. The main process is used to manage child processes, create sockets, receive client requests, and send client requests to child process processing;
3. The child process is responsible for processing client requests and building and sending response messages;
4. A child process can only process and respond to requests from a client;
5.HTTPD the default MPM module;

Worker: multiplexed multi-process IO Model (multi-process multithreading)
1. A master process, multiple sub-processes;
2. The main process is used to manage child processes, create sockets, receive client requests, and send client requests to child process processing;
3. The child process is responsible for managing the threads within it;
4. Thread is responsible for processing client requests and building and sending response messages;
5. A thread can only process and respond to requests from a client;

Event: multiplexed IO Model (event-driven multi-process model)
1. A master process, multiple sub-processes;
2. The main process is used to manage child processes, create sockets, receive client requests, and send client requests to child process processing;
3. The child process is responsible for processing client requests and building and sending response messages;
4. A child process can process and respond to requests from multiple clients;

Note: The event model is not supported prior to httpd-2.0; it is used only as a test in the httpd-2.2 version and is defined as the recommended model only in httpd-2.4;

In CentOS 6, only the httpd-2.2 version can be installed through the RPM package, the event model is a test model and does not support DSO dynamic loading and unloading;
In CentOS 7, the httpd-2.4 version can be installed through the RPM package, the event mode is "production ready" and supports DSO dynamic loading and unloading;


Features of the httpd:
Support for CGI (Common Gateway Interface);
Web hosting: Virtual Host
How the virtual host is identified:
IP + PORT + FQDN
Reverse Proxy: Reverse Proxy
Load Balancer cluster:
Based on flow, bytraffic
Business-based, bybusiness
Based on the request, byrequest
Settings for the alias of the path name
Authentication:
Basic
Digest
Support Rich third-party modules;


Program Environment:

CentOS 6:
Program Composition:
HTTPD: Main Package
Httpd-tools: Toolkit
Httpd-manual: Offline Help documentation

Program Environment:
/ETC/HTTPD/CONF/HTTPD.CONF:HTTPD master configuration file;
/etc/httpd/conf.d/*.conf: Fragment configuration file;
Startup scripts for/ETC/RC.D/INIT.D/HTTPD:HTTPD services;
/ETC/RC.D/INIT.D/HTTPD Start|stop|reload|restart
Servcie httpd Start|stop|reload|restart
/ETC/SYSCONFIG/HTTPD:/ETC/RC.D/INIT.D/HTTPD configuration file;
/usr/lib64/httpd/modules: The storage path of dynamic module;
/etc/httpd/modules-/usr/lib64/httpd/modules
/etc/httpd/conf/magic: A configuration file that implements the MIME function;
/VAR/LOG/HTTPD:HTTPD the path where log files are stored, including access logs and error logs;
/etc/httpd/logs-/VAR/LOG/HTTPD
/VAR/RUN/HTTPD: The file that holds PID of httpd main process;
/etc/httpd/run-/VAR/RUN/HTTPD
/var/www/html: The mapping path of the default Web site's document root directory;

Executable Program Files:
/USR/SBIN/HTTPD: The core program file to start the MPM prefork model;
/usr/sbin/httpd.event: Start the event model;
/usr/sbin/httpd.worker: Start the worker model;
/USR/SBIN/APACHECTL: A Service control command that is used to start or stop a service;

CentOS 7:
httpd-2.4
Program Composition:
HTTPD: Main Package
Httpd-tools: Toolkit
Httpd-manual: Offline Help documentation

Program Environment:
/ETC/HTTPD/CONF/HTTPD.CONF:HTTPD master configuration file;
/etc/httpd/conf.d/*.conf: Fragment configuration file;
/usr/lib/systemd/system/httpd.service: Unit File used when starting the service;
Systemctl Start|stop|restart|reload Httpd.service
/ETC/SYSCONFIG/HTTPD:/ETC/RC.D/INIT.D/HTTPD configuration file;
/usr/lib64/httpd/modules: The storage path of dynamic module;
/etc/httpd/modules-/usr/lib64/httpd/modules
/etc/httpd/conf/magic: A configuration file that implements the MIME function;
/VAR/LOG/HTTPD:HTTPD the path where log files are stored, including access logs and error logs;
/etc/httpd/logs-/VAR/LOG/HTTPD
/VAR/RUN/HTTPD: The file that holds PID of httpd main process;
/etc/httpd/run-/VAR/RUN/HTTPD
/var/www/html: The mapping path of the default Web site's document root directory;

Executable Program Files:
/USR/SBIN/HTTPD:
In the httpd-2.4 version, MPM supports the DSO mechanism, and each MPM model has a corresponding module;
/usr/lib64/httpd/modules/mod_mpm_prefork.so
/usr/lib64/httpd/modules/mod_mpm_worker.so
/usr/lib64/httpd/modules/mod_mpm_event.so
/USR/SBIN/APACHECTL: A Service control command that is used to start or stop a service;

Basic knowledge related to HTTP protocol

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.