Learn more about Apache: Basic Introduction and Configuration

Source: Internet
Author: User
Learn more about Apache: Basic Introduction and configuration-Linux Enterprise Application-Linux server application information. See the following for details. Apache Introduction


(1)

Preface

-------

I think linux enthusiasts do not know about Apache. as a linux administrator, you should be more proficient in Apache configuration. here I will describe Apache in my understanding. as a widely used Web server, Apache puts reliable first, and performance is only the second. I think this idea is good. of course, the best part of it is open source code, which gives us the opportunity to gain a deeper understanding of the world's most popular Web Server.


Ii. Basic Structure

---------------

Apache is composed of modules, among which http_core.c is the most fundamental. A minimum Apache compilation only contains this module. you can use "httpd-l" to list the modules compiled by Apache. the dynamic module needs to be defined in the preparation file. in Redhat, only "http_core.c" is compiled, and the rest are compiled into so. it can be dynamically loaded by Apache. apache in Redhat is special. The standard Apache only has one configuration file httpd. conf. Other files are empty.


The following is a command to load modules in the preparation file:


LoadModule digest_module modules/mod_digest.so

LoadModule proxy_module modules/libproxy. so

LoadModule php3_module modules/libphp3.so

......

ClearModuleList

AddModule mod_actions.c

AddModule mod_userdir.c

AddModule mod_alias.c

......


LoadModule is used to dynamically load modules. clearModuleList is used to delete the list of modules in Apache. addModule adds modules to the list. the above command is used to re-construct the module list. The order in the list represents the priority of the module during processing, and the subsequent priority is high.


Apache processes a Clinet request as follows:


1. URL-> Filename translation

2. Auth ID checking

3. Auth access checking

4. Access checking other than auth

5. Determining MIME type of the object requested

6. Fixups

7. Actually sending a response back to the client

8. Logging the request


Apache is only responsible for memory allocation, IO, process management, module management, etc. It calls the interface functions provided by the module to complete command preparation and actual processing of user requests. the core module http_core.c provides the most basic commands, and each module usually has its own preparation commands. the module can participate in the above eight steps. each module provides a struct module, which defines a large number of function pointers and structure pointers. The struct module tells Apache about the commands supported by this module and the steps involved.


The struct module defines the name of the module to be changed. This is done through a macro, and its name is _ FILE _. Therefore, the module name defined in the FILE mod_foo.c is called mod_foo.c.


Apache maintains a linked list (the header pointer is top_module). At first, there was only one

Http_core.c. each Command LoadModule, AddModule. add one item to the header. in each step, Apache calls the functions provided by each module in sequence in the linked list. in many steps, the first return of OK is the end of Apache. therefore, the order in the table (this is the so-called priority) can have a great impact on the system.


Let's take a look at the eight steps mentioned above:


1. URL-> Filename translation

Convert the URL to a local file name. For example, mod_alias.c will process alais in this step.


2. Auth ID checking

3. Auth access checking

4. Access checking other than auth

Perform authentication


5. Determining MIME type of the object requested

Determine the MIME type of the requested object


6. Fixups

I don't know (please let me know)


7. Actually sending a response back to the client

Send response to customer


8. Logging the request

Write log


The authentication section will be explained later. Let's take a look at the last few steps. Apache inherits the method that uses the extension to determine the MIME type. AddType is used to add new extensions:


AddType application/x-httpd-php3. php3

AddType application/x-tar. tgz


These two commands define the MIME type of files suffixed with php3 and tgz. the standard MIME type is used here. The so-called determine MIME type also includes another situation: the module will use some strings to describe a request, apache selects a module based on this string to process the request. these strings are internally customized. the details are described below.


AddHandler cgi-script. cgi

AddHandler server-parsed. shtml


Sethandler cgi-script


AddHandler defines which extension is described using that string.

SetHandler specifies that all files in a directory are described using this string.


The commands I mentioned here are closely related to their structures. the relationship between Handler and Type is described below. A lot of things can't be seen clearly from the outside. Below, we can see from the inside.


Basic Structure of three programs

-----------------

Apache has good cross-platform performance. to achieve this goal and simplify the workload of module writers, Apache has completed many basic functions such as IO and memory allocation. These interfaces are irrelevant to specific platforms. there are also some useful routines such as hash table and array. in the whole system, Apache has a basic point. It tries its best to use simple structures and algorithms, which is not only easy to understand and maintain, but also improves its stability.


On UNIX systems, Apache adopts a multi-process model and a multi-thread model on Windows. in the multi-process model, its child processes process customer requests. The parent process is used to manage child processes. when the system is overloaded, the parent process starts several more child processes. When the system is idle, the parent process will kill several child processes. the number of sub-processes is between "MinSpareServers" and "MaxSpareServers. the number of requests processed by each sub-process is also limited, which can solve problems such as memory leakage. all process statuses are recorded in share memory. since the status of each process is recorded in a small memory, it usually only writes this memory. Therefore, Apache does not use any synchronization mechanism.


Apache uses several multi-process server models mentioned in Richard Steve's book. Different methods are used on different systems based on their characteristics:


1. accept:

The accept is blocked only when the accept is implemented at the kernel level.

2. select:

Blocking at select.

3. mutex/lock_file:

Use mutex or lock_file to perform mutual exclusion on accpet.


Blocking is required for all three methods. The difference is that blocking is different from blocking. the first two methods are caused by the so-called mass problem: multiple processes that are blocked on the same resource are simultaneously awakened, causing further competition. however, according to Richard Steve's evaluation, the first method is the fastest, the second method is the second, and the third method is the slowest. in fact, the first three methods in linux also have major issues.


Although Apache does not emphasize performance, it does not mean that they do not pay much attention to performance. However, Apache considers realiable on the Server as the first priority. However, Apache's performance is still good.

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.