5th Chapter Web Server

Source: Internet
Author: User

1, the Web server has different forms: you can install and run a common software Web server on a computer system, a Web server device, or implement an embedded Web server on a small number of computer chips.


2. First step-Receive client connection

When a client requests a TCP connection to a Web server, the Web server establishes a connection to determine which client is at the other end of the connection and resolves the IP address from the TCP connection.


3, the second step-receive the request message

When data arrives on the connection, the Web server reads the data from the network connection and parses the contents of the request message.

The single-threaded Web server processes only one request until it finishes. You can use a multithreaded Web server or a server that re-uses I/O. In a multiplexed structure, you want to monitor the activity on all connections at the same time. When the state of the connection changes, a small amount of processing is done on that connection; after processing is finished, the connection is returned to the Open connections list, waiting for the next state change. You can combine multithreaded and multiplexed I/O.


4, the third step-processing the request

Once the Web server receives the request, it can process the request based on the method, resource, header, and optional body part.


5, the fourth step-mapping and access to resources

The Web server is a resource server. They are responsible for sending pre-created content. Typically, a special folder in the file system of a Web server is dedicated to hosting Web content, which is referred to as the root directory of the document. The Web server obtains the URI from the request message and attaches it to the back of the document's root directory. The server should be aware that the relative URL cannot be left out of the root directory, exposing the rest of the file system.

A virtual-hosted Web server provides multiple Web sites on the same Web server, each with its own unique document root directory on the server.

Another common application of the root directory is to provide people with a private web site on the Web server.

A Web server can receive a request for a directory URL, and its path can be resolved to a directory, not a file. Most Web servers will look for a file named index.html in the directory to represent this directory. If a user requests a directory URI, does not provide a default index file, and does not prohibit the use of a directory index, many Web servers automatically return an HTML file that lists the file names in that directory, as well as the size and modification date of each file, and also includes a URI connection to each file.

Apache allows the user to map the URI pathname component to the executable directory. When the server receives a request for a URI with an executable path component, it tries to execute the program in the appropriate server directory.


6. Fifth Step-build response

6.1. MIME type

The Web server is responsible for determining the MIME type of the response body, and there are many ways to associate a MIME type with a resource.

The Web server can use the file's extension to describe the MIME type; the Apache Web server scans the contents of each resource and matches it to a known schema table to determine the MIME type of each file; The Web server can be configured so that it does not take into account the file's extension and content. Forces a specific file or directory content to have a MIME type, and some Web servers are configured to store resources in a variety of document formats, allowing them to decide which best to use by negotiating with the user.


7. Sixth Step-Send response

The server wants to record the status of the connection, and also pay special attention to the processing of the persistent connection. For non-persistent connections, the server should close its own end of the connection after sending the entire message.


8, the seventh step-record the log

When the transaction ends, the Web server adds an entry in the log file to describe the transaction that was executed.

This article from "Lotus's Thoughts" blog, please be sure to keep this source http://liandesinian.blog.51cto.com/7737219/1557913

5th Chapter Web Server

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.