web servers come in various forms
A general-purpose software web server that can be installed and run on standard computer systems
Can be purchased The software in the web server device will be pre-installed and configured
A web server can be embedded on a small number of computer chips
what the web server does
Establish a connection ------ accept a client connection Accept the request ------ read an HTTP message request from the network Process the request------interpret the request message Access resource ------ access the resource specified in the message Build Response - Create HTTP response message with correct headers send response ------ send the response to the client Log transaction process ------ record the contents of the completed transaction in a log file
This is how a web server accomplishes its basic tasks
The first step ------ accept the client connection
After the client receives a connection, it will add the new connection to the list of existing web server connections to monitor the data transfer on the current connection. During the period, the server should also prevent the connection of unauthenticated or known malicious black clients through a certain device mechanism. The relevant identification technologies include: client host name identification, client user identification through ident, etc.
The second step ------ request message
-
Parse the request line to know the method, url, protocol version, and crlf character
-
Parse to get the header ending with crlf
-
get an empty line ending with crlf, marking the end of the header (if any)
-
Parse to get the body, (if any)
-
The web service may also store the request message in an internal data structure that it can process quickly!
-
Different server configurations indicate what transactions it can handle at the same time:
-
Single-threaded web server: Only one request can be processed, and the next request can be processed after the current request is processed! Advantages: Simple to implement, suitable for low-load servers. Disadvantages: Other requests cannot be processed in a timely manner, which may easily lead to long delays and lead to performance problems.
-
Multi-threaded and multi-process web server: can handle multiple requests at the same time! Pros: Responsiveness. Disadvantages: complex construction, easy to quickly cause excessive memory consumption and crash! Ideally, there should be a limit to the number of connections that can be handled at the same time!
-
Web server that reuses i/o: reuse i/o
-
Multiplexing i/o and multithreaded web servers: a combination of 2 and 3
The third step ------ process the request
Once the web server receives the request. The request can be processed according to the method, resource, header and optional body part
The fourth ------ mapping and access to resources
-
A path mapping relationship for requesting resources is introduced here. To put it bluntly, it is to find the directory path of the client's request resource on the server! Related concepts are: docroot (document root directory), the upper-level directory that does not allow access to the root directory.
-
Virtually hosted docroot: Several web sites are hung on a server, so when the requested resource paths are the same, the server should find the real resource directory from the host and uri fields in the header of the request message. These directories are all available configured