Web Server
Get startedBefore Apache, we should familiarize ourselves with the Web server, because Apache is also a type of Web server.
The web system consists of a client (browser) and a server. The web system architecture is also called the B/S architecture. The most common Web servers include Apache and IIS. common browsers include IE, Firefox,Chrome. To access a webpage, you need to enter the URL (Uniform Resource Locator) of the webpage in the address bar of the browser or link to the webpage through a hyperlink. The browser sends an HTTP request to the server where the webpage is located. The server processes the received request information and returns the result to the browser, finally, the results processed by the browser are displayed to the user.
WebServer SideWorkflow:
(1) the client sends a request
Client (via browser)Establish a TCP connection with the Web server. After the connection is established, an access request (such as get) is sent to the web server ). According to the HTTP protocol, the request contains a series of information such as the Client IP address, browser type, and request URL.
(2) Server Resolution request
The Web server decodes requests based on the HTTP protocol to determine further actions. The design content includes three key points: method (get), document (/sample.html) and the protocol used by the browser (HTTP/1.1). The method tells the server to complete the action. The meaning of the get method is obviously: the server should locate, read, and return the file to the customer.
The web server software now knows that it should find the file/sample.html and use the HTTP/1.1 protocol to return the memory to the customer. The information is sent through the same connection as the request, so the server does not need to determine whether the customer or create a new connection.
(3) read other information (optional)
The Web server reads other parts of the request as needed. In HTTP/1.1, the customer should also provide some information about the server. Metainformation can be used to describe the browser and its capabilities, so that the server can determine how to return a response accordingly.
(4) request Completion
If no error occurs now,The WWW server will perform the requested action. To obtain (get) a document, the web server searches for the requested file (/sample.html) in its document tree ). This is done by the file system on the server machine as part of the operating system. If the file can be found and can be read normally, the server returns it to the customer.
If successful: the file is sent out.
First, the web server sends a status code and some descriptions. Now that the file has been found, the sending status code 200 indicates that everything is OK. The document is sent later. Because the sent information is an HTML document, the Content-Type value is text/html. The document length is 1024 bytes, so the Content-Type value is 1024. The identifier of the server software and the time attribute information of the file are also included in the header domain.
If it fails, an error is returned.
If the requested file is not found or found but cannot be read, the test request cannot be met. In this case, a status code different from 200 is returned. The most common problem is that the file name in the request is incorrectly spelled, so the server cannot find the file. In this case, the server will send a status code --- 404 to the customer.
(5) close the file and network connection and end the session.
When the file has been mailed or the error has been sent,The Web server ends the entire session. It closes the opened requested file, closes the network port, and ends the network connection. Other work is done by the client, including receiving data and rendering it in a user-readable manner. These are not related to servers.
Apache Architecture
ApacheAs the oldestWebServer, alwaysWebThe first choice of application systems is widely used in the world.WebServer software, which can run on almost all widely used computer platforms, is the most popular because of its wide use of cross-platform and security.WebOne of the server-side software is also a popular ArchitectureLampIs an important part.
As the most popular Web server in the world, Apache follows the same http protocol. The default port number is 80. The following figure shows the Apache architecture.
ApacheFeatures:
- Supports the latest HTTP/1.1 communication protocol. Apache is one of the first web servers that use HTTP/1.1. It is fully compatible with HTTP/1.1 and is backward compatible with HTTP/1.0. Apache has made necessary preparations for all the content provided by the new protocol.
-
- Supports multiple computer platforms. Apache can run on almost all computer operating systems, including mainstream UNIX, Linux, and Windows operating systems.
-
- The configuration file is simple and easy to operate. You can modify Apache directly by modifying the configuration file information of Apache.
-
- Supports real-time monitoring of server status and custom server logs. Apache provides great flexibility in logging and monitoring the running status of the server. You can monitor the status of the server through a Web browser, or customize the log as needed.
-
- Supports multiple HTTP authentication methods.
-
- Supports web directory modification. You can use a specific directory as a web directory.
-
- Supports CGI scripts, such as Perl and PHP.
-
- Supports server-side commands (SSI ).
-
- Supports Secure Socket Layer (SSL ).
-
- FastCGI is supported.
-
- Supports virtual hosts. That is, multiple HTTP services are provided by using different host names on one server. Apache supports three types of virtual host services: IP address, host name, and port number.
-
- Trace user sessions. When you browse APACHE-based web sites, you can track them through the mod_usertrack module of Apache.
- Supports dynamic shared objects. Apache modules can be dynamically loaded at runtime, which means these modules can be loaded into the server process space, thus reducing the system memory overhead.
-
- Supports multiple processes. When the load increases, the server will quickly generate sub-processes for processing, thus improving the system response capability.
-
- Supports functional modules provided by third-party software developers. For example, Apache can support Java Servlet after loading the mod_jserv module, so that Java applications can be run.Program.
-
- MPM supporting multi-threaded and multi-process hybrid models. When the MPM type is specified as worker, because it is handled by threads, it can process a large number of requests, and the overhead of system resources is smaller than the process-based server.
ApacheWork Simulation
Apache 2.x supports plug-in parallel processing modules, it is called a multi-path processing module ( MPM ). Compile apache only one MPM , for the class UNIX system, there are several different MPM Available, which affects apache speed and scalability.
worker MPM : multiple sub-processes are used, each sub-process has multiple threads. Each thread processes a request. MPM it is usually a good choice for high-traffic servers. Because it is better than prefork MPM requires less memory and is more scalable.
Prefork mpm:Multiple Sub-processes are used, but each sub-process does not contain multiple threads. Each process processes only one connection. In many systems, its speed andWorker mpmFaster, but more memory is needed. This wireless process is designed to be superiorWorker mpmBecause it can be applied to third-party modules that do not have thread security (suchPhp3/4/5And is easier to debug on platforms that do not support thread debugging.Worker mpmHigher Stability.
(If the two modes and more settings and monitoring of Apache are described later)