I. Basic Definitions of HTTP
Hyper Text Transfer Protocol (HTTP) was designed to provide a method for publishing and receiving HTML pages. Resources requested through HTTP or HTTPS are identified by the Uniform Resource Identifier (URI. Currently, three versions are available: http/0.9, http/1.0, And/http/1.1. Currently, http/1.0 and 1.1 are widely used.
Http/0.9: used to transmit HTML documents only;
Http/1.0: supports multimedia data processing, keep-live (persistent connection), and cache;
Http/1.1: supports more request methods and finer Cache control; persistent connections;
Ii. HTTP request process
The http transaction process is: a request and its corresponding response.
Http request: request
Format
<
method
> <
request-URL
> <
version
>
<
headers
>
<
entity-body
>
Http response: response
Format
<
version
> <
status
> <
reason-phrase
>
<
headers
>
<
entity-body
>
Method request method; the actions you want the server to execute; Resources for request-URL requests such as GET, POST, and HEAD; can be relative paths (relative host location ); it can also be the complete URLversion Protocol version. Format: http/<major>. <minor> headershttp header information status code reason-phrase reason phrase; Numeric status readable information entity-body subject
A complete request process:
Because http is a stateless (stateless) protocol, the identity of each requester cannot be recorded, and the request is closed immediately after the end of each request. Therefore, each request must first go through DNS resolution, three handshakes, and four disconnections. Therefore, the CPU-consuming clock cycle is a waste of resources. There are two methods to provide efficiency:
1. Parallel requests: Initiate multiple requests at the same time and return multiple responses (the first request can only be one resource );
2. persistent connection: requests are continuously opened after three handshakes. The client can continue the request. The fault is that persistent connections will occupy resources;
Disconnection mode: two methods are used to disconnect a device, no matter which one reaches the upper limit.
Timeout: specifies the time limit for a persistent connection after the connection
Maximum number of requested resources: Maximum number of resources allowed for connection
Iii. HTTP Request Method and response status code
Http request methods include GET, HEAD, POST, DELETE, PUT, OPTIONS, TRACE.... The first five methods are commonly used.
The GET request obtains a resource. The server needs to send a HEAD request to a resource, but the server does not need to send resources, but only returns the response's first information. The POST submission form supports HTML form submission; the form contains user-filled data. The data is sent to the server. The server stores the data to a certain location, and the PUT file is written to the server; for example, release the system DELETE request to DELETE the resource OPTIONS pointed to by the URL to detect the request method supported by the server for a resource TRACE request resource transmission through the firewall, proxy or gateway and other CONNECTHTTP/1.1 protocol pre-leave the Proxy Server Extension methods LOCK, MKCOL, COPY, MOVE...
There are five status codes in the http response:
1xx: Information Status Code
2xx: Success status code
200: OK
201: created
3xx: redirect status code
301: Moved Permanentl; Use the header "Location: URL" in the Response Message; specify the current Location of the Resource
302: Fonud (temporary redirection); Use the header "Location: URL" in the Response Message; specify the Location of the temporary resource
304: Not Modified (the cache can be used). The client is notified that the resource has Not been changed.
4xx: client error message
403: Forbidden; the request is rejected by the server
404: Not Found; the server cannot find the requested URL
405: Method Not Allowed; you are Not Allowed to use this Method to request the corresponding URL.
5xx: server error message
500: Internal Server Error; Internal Server Error
502: Bad Gateway; the proxy server receives a pseudo response from the superior
503: Service Unavailable; the server cannot provide services at this time, but may be available in the future
Web Service input/output structure:
1. Single-thread I/O structure: a single thread responds to a single request
2. multithreading I/O structure: multiple threads respond to corresponding requests
3. Reusable I/O structure: a single thread responds to multiple requests
4. Reusable multi-threaded I/O structure: multiple threads; a single thread responds to multiple requests
Iv. Introduction to httpd software for web Services
There are many http software in linux. For example, apache: httpd and nginx. Here we will introduce httpd.
Httpd attribute: highly modular. It can be dynamically loaded and detached. The main mode is the combination of core and modules. MPM (Multipath Processing Module) is also supported: multi-channel Processing Module. It is not a module, but a name for a feature.
MPM corresponds to the web Service parallel structure module:
Prefock: Pre-fock; one process and one request.
When a request is sent, the web Service itself should not respond to the request; instead, it should fock itself a sub-process to respond to the process; and the fock requires time to generate a sub-process; therefore, when the request comes, in advance, some processes are fock to wait for the request to respond, and some idle sub-processes are kept waiting for other requests.
Worker: multiple threads in a process; one thread and one request.
Multiple Threads are generated by multiple processes. Each thread corresponds to one request. If multiple requests request the same resource under one process, resources can be shared. However, it is because a single thread responds to the request; scheduling switching is required; the switching process is a waste of resources. The performance is similar to that of prefock.
Event: A process responds to requests.
Based on event-driven, a single thread responds to multiple requests. Corresponds to the reusable multi-thread I/O structure in the web parallel structure.
Httpd version:
Httpd-1.3; httpd-2.0; httpd-2.2; httpd-2.4; four versions. Currently, 2.0-2.4 are in maintenance status on the official website.
Some important features of httpd:
Path alias: alias
User authentication: authentication
Virtual host: virtual host
Reverse Proxy:
Server Load balancer:
User site:
CGI: Common Gateway Interface
5. Install httpd
You can first check whether the system is installed
123
[Linux]
#rpm -qa httpd
httpd
-
2.2
.
15
-
29.el6
.centos.x86_64
# Display version 2.2.15 installed
If the system is not installed, you can configure the yum source before installing it.
[Linux]
#yum -y install httpd
# After installation, you can view the installation details and specific directories.
[Linux]
#rpm -ql httpd
/
etc
/
httpd
/
etc
/
httpd
/
conf
/
etc
/
httpd
/
conf.d
/
etc
/
httpd
/
conf.d
/
README
/
etc
/
httpd
/
conf.d
/
welcome.conf
/
etc
/
httpd
/
conf
/
httpd.conf
/
etc
/
httpd
/
conf
/
magic
/
etc
/
httpd
/
logs
/
etc
/
httpd
/
modules
/
etc
/
httpd
/
run
/
etc
/
logrotate.d
/
httpd
/
etc
/
rc.d
/
init.d
/
htcacheclean
/
etc
/
rc.d
/
init.d
/
httpd
/
etc
/
sysconfig
/
htcacheclean
/
etc
/
sysconfig
/
httpd
/
usr
/
lib64
/
httpd
# Start after installation
[Linux]
#service httpd start
Starting httpd: [ OK ]
[Linux]
#ps aux | grep httpd
root
3422
0.0
0.7
184284
3844
? Ss
16
:
20
0
:
00
/
usr
/
sbin
/
httpd
apache
3425
0.0
0.6
184420
3052
? S
16
:
20
0
:
00
/
usr
/
sbin
/
httpd
apache
3426
0.0
0.6
184420
3144
? S
16
:
20
0
:
00
/
usr
/
sbin
/
httpd
apache
3427
0.0
0.6
184420
3052
? S
16
:
20
0
:
00
/
usr
/
sbin
/
httpd
apache
3428
0.0
0.6
184420
3068
? S
16
:
20
0
:
00
/
usr
/
sbin
/
httpd
apache
3429
0.0
0.6
184420
3068
? S
16
:
20
0
:
00
/
usr
/
sbin
/
httpd
apache
3430
0.0
0.4
184284
2440
? S
16
:
20
0
:
00
/
usr
/
sbin
/
httpd
apache
3431
0.0
0.4
184284
2440
? S
16
:
20
0
:
00
/
usr
/
sbin
/
httpd
apache
3432
0.0
0.4
184284
2440
? S
16
:
20
0
:
00
/
usr
/
sbin
/
httpd
Enter the corresponding IP address in the browser after the startup is successful.
The preceding interface indicates that the instance has been installed and started successfully. The basic introduction and installation have been completed. The configuration parameters of httpd and the compilation and installation of version 2.4 are described in detail in the next section of Web Service (ii) httpd configuration parameters.
This article is from the "Soul" blog, please be sure to keep this source http://chenpipi.blog.51cto.com/8563610/1379763