The configuration file of the Apache server is located in the usrlocalapacheconf directory. Traditionally, three configuration files httpd. conf, access. conf, and srm. conf are used to configure the behavior of the Apache server. Httpd. conf provides the most basic server configuration, which describes how the daemon httpd runs. srm. conf is a service.
The configuration file of the Apache server is located in the/usr/local/apache/conf/directory. Traditionally, three configuration files are used: httpd. conf, access. conf and srm. conf to configure the behavior of the Apache server. Httpd. conf provides the most basic server configuration, which describes how the daemon httpd runs. srm. conf is a service.
The setting file is located in the/usr/local/apache/conf/directory.
File httpd. conf, access. conf, and srm. conf.
Httpd. conf provides the most basic
Is a technical description of how the daemon httpd runs. srm. conf is
Resource ing file, tell
MIME types of various files, and how to support these files; access. conf is used
Control the access permissions of different users and computers.
For the normal operation
You need to set these three files.
In addition to these three settings files, Apache uses the mime. types file to identify different files.
For the corresponding MIME type, the magic file sets some special identifiers for different MIME types, so that Apache
When the MIME type of a file cannot be determined from the document suffix, the MIME type of the file can be determined through these special marks in the file content.
Bash-2.02 $ ls-l/usr/local/apache/conf
-Rw-r -- 1 root wheel 348 Apr 16 16:01 access. conf
-Rw-r -- 1 root wheel 348 Feb 13 access. conf. default
-Rw-r -- 1 root wheel 30331 May 26 08:55 httpd. conf
-Rw-r -- 1 root wheel 29953 Feb 13 httpd. conf. default
-Rw-r -- 1 root wheel 12441 Apr 19 :42 magic
-Rw-r -- 1 root wheel 12441 Feb 13 magic. default
-Rw-r -- 1 root wheel 7334 Feb 13 mime. types
-Rw-r -- 1 root wheel 383 May 13 srm. conf
-Rw-r -- 1 root wheel 357 Feb 13 srm. conf. default
In fact, in the current version of Apache, all the original httpd. conf, srm. conf, and access. conf
All parameters are placed in one
In the httpd. conf file, only three configuration files are used for compatibility with previous versions (the three configuration files are used in NCSA-httpd mode ).
File. The access. conf and srm. conf files provided do not have specific settings.
In the new version of Apache, all the settings are placed in httpd. conf, so you only need to adjust the settings in this file. The following uses the httpd. conf provided by default as an example to explain how
Configuration options of the server. However, you don't have to worry about providing too many parameters. Basically
The parameters are clear, or you can run Apache without modifying it.
. However, if you need to adjust the Apache service
You need to understand the meaning of the parameters.
There is a lot of controversy over the Internet. Basically, users who use Apache have almost no doubt about its excellent performance. Apache also supports many well-known high-load websites, however, in the evaluation of commercial organizations, Apache often has a low score. Many people pointed out that in these evaluations, commercial Web
And its operating systems are often adjusted by the engineers of their professional companies, while the Free operating system and Web
The default value is often used.
Or just make small changes. In addition to the performance adjustment of the operating system
It is by no means the most optimized and efficient, but to adapt to the setting of almost all types of operating systems and all types of hardware. multi-platform software cannot provide the optimal default for specific platforms and specific hardware.
. Therefore, performance adjustment is essential when Apache is used.
Another fact ignored in business evaluation is that different types of functions are often compared during evaluation.
For example, the performance of Standard CGI using Apache, ISAPI, and NSAPI
API comparison, in fact, Apache
The functions that can be compared with modperl, FastCGI, and PHP are similar to ASP. However, due to the open mode of Apache, these functions are developed by independent developers, implemented as an independent module. However, during the evaluation, the tester did not add a corresponding module to evaluate its performance.
Running Parameters of the HTTP daemon
Httpd. conf defines the parameters required by the httpd daemon to determine the running mode and environment.
The default value is standalone and httpd.
It will be started by itself and will reside in the host to monitor connection requests. In Linux, the Web will be automatically started in the startup file/etc/rc. d/rc. local/init. d/apache.
This method is recommended.
The other method is the inet method.
Inetd monitors connection requests and starts
. When you need to use the inetd startup method, you need to change it to this setting and block/etc/rc. d/rc. local/init. d/apache file, and change/etc/inetd. conf and restart inetd, then Apache can start from inetd.
The difference between the two methods is that
Manage your own startup processes.
Multiple copies, each of which reside in the memory. A connection request can be processed immediately without the need to generate a sub-process. The response to client browser requests is faster and the performance is better.
High. The inetd method starts http only after inetd discovers a connection request.
Because the inetd needs to listen to too many ports, the response is slow and the efficiency is low, but the Web
Resources used. Therefore, the inetd method is only used for access that is occasionally accessed and does not require access speed.
. In fact, the inetd method is not suitable for http burst and multi-connection features, because a page may contain multiple images, and each image will cause a connection request, even though the number of visitors causes less teaching, however, there are many transient connection requests, which are limited by the performance of inetd and may even affect other inetd-Enabled
ServerRoot is used to specify the running directory of the daemon httpd. After httpd is started
The current directory of the process is changed to this directory. Therefore, if the specified file or directory is
The actual path is located under the path defined by ServerRoot.
Because httpd often performs concurrent file operations, it is necessary to use the locking method to ensure that file operations do not conflict. Due to the limited file lock capabilities of the NFS file system, therefore, this directory should be a local disk file system instead of an NFS file system.
# LockFile/var/run/httpd. lock
The LockFile parameter specifies the lock file of the httpd daemon. You do not need to set this parameter.
The operation is automatically performed in the path under ServerRoot. However, if ServerRoot is an NFS file system, you need to use this parameter to specify the path in the local file system.
The process Number of the httpd daemon is recorded in the file specified by PidFile. Because httpd can automatically copy itself, there are multiple httpd processes in the system, but only one process is the process initially started, it is the parent process of other processes. sending signals to this process affects all httpd processes. The process Number of the httpd parent process is recorded in the file defined by PidFILE.
Httpd uses ScoreBoardFile to maintain internal data of a process. Therefore, you do not need to change this parameter unless the administrator wants to run several Apache
In this case, each Apache
You must set the htt pd. conf file independently and use different scoreboardfiles.
# ResourceConfig conf/srm. conf
# AccessConfig conf/access. conf
The two parameters ResourceConfig and AccessConfig are used to be compatible with the old version of Apache that uses the srm. conf and access. conf file. If there is no compatibility requirement, you can specify the corresponding setting file as/dev/null. This indicates that no other setting file exists and only httpd is used. conf file to save all the settings.
Timeout defines the client program and
The timeout interval of the connection. After the timeout interval (in seconds) is exceeded
The connection to the client is closed.
In HTTP 1.0, only one HTTP request can be transmitted over one connection, while the KeepAlive parameter is used to support one connection and multiple transmission functions in HTTP 1.1, in this way, multiple HTTP requests can be transmitted in a connection. Although this function is only supported by newer browsers, this option is still enabled.
MaxKeepAliveRequests is the maximum number of HTTP requests that a connection can perform. Set
If the value is set to 0, infinite transmission requests can be made in one connection. In fact, no client program requests too many pages in a single connection. Generally, the connection is completed if this limit is not reached.
KeepAliveTimeout tests the time between multiple request transmissions in a connection. If
A request has been completed, but the next request of the customer program has not been received. The interval exceeds
After the value set for this parameter,
MinSpareServers 5 MaxSpareServers 10
In the Web
Because the sub-process must be generated first to process the customer's request, the response time is a little delayed. However, Apache
A special technique is used to get rid of this problem. This means that multiple idle sub-processes are generated in advance and reside in the system. Once a request occurs, immediately use these idle sub-processes for processing, so that there is no latency caused by the generation of sub-processes. As client requests increase, the number of sub-processes started increases.
After an HTTP request is processed, the copy does not exit immediately, but stays in the computer waiting for the next request. However, the number of idle sub-process Replicas cannot be increased or decreased, and too many idle sub-processes are not processed or occupied.
Therefore, we need to limit the number of spare copies to maintain an appropriate number, so that we can respond to customer requests in a timely manner and reduce the number of unnecessary processes.
Therefore, you can use the MinSpareServers parameter to set the minimum number of idle sub-processes and
Use the MaxSpareServers parameter to limit the maximum number of idle sub-processes, redundant
It will quit. According
High Performance and
If these parameters are frequently accessed, you must increase the settings of these two parameters. For high-load professional websites, these two values
It should be roughly the same and equivalent to the most supported by the system
Number of replicas and unnecessary replicas
The StartServers parameter is used to set the number of subprocess replicas started at httpd startup. this parameter is related to the MinSpareServers and MaxSpareServers parameters defined above and is used to start idle sub-processes to increase
Response speed. This parameter should be set to a value between the first two values, which is less than MinSpareServers and greater than MaxS pareServers.
On the other hand,
After all, the capability is limited, and it is impossible to process unlimited connections at the same time.
Therefore, the Maxclient s parameter is used to specify
The maximum number of customers that support concurrent access. If this value is too large, the system has to switch between too many processes during busy hours to serve too many customers, this slows down the response to each customer and reduces the overall efficiency. If this value is set to a small value, some customer connection requests will be rejected when the system is busy. When
When the performance is high, you can add the setting of this value as appropriate. Professional websites should be improved
Therefore, this parameter cannot exceed the limits of the hardware. If access is denied frequently, it indicates that the hardware needs to be upgraded.
Hardware. For non-professional websites, users are not very concerned about the response speed to the customer's browser, or think that the response speed is slower than that of the rejected connection. This parameter can also be set slightly beyond the hardware conditions.
This parameter limits the settings of MinSpareServers and MaxSpareServers.
A sub-process is a commonly used method for providing Web services. A sub-process is a connection service, the problem is that each connection requires system operations to generate and exit sub-processes, so that these additional processes occupy a large amount of processing capabilities of the computer. Therefore, the best way is that a sub-process can connect to the service for multiple times, so that the system consumption of the generated and exited processes is not required. Apache uses this method. After a connection is completed, the sub-process does not exit, but stays in the system waiting for the next service request, which greatly improves the performance.
However, due to the constant application and release of memory by the neutron process during the processing process, an increase in the number of times will cause
Some memory spam will affect the system stability and the effective use of system resources. Therefore, after a replica processes requests for a certain number of times, the child process can be exited and then exited from the original
Re-copy a clean copy in the httpd process to improve system stability. In this way, each
The number of service requests processed by sub-processes is defined by MaxRe questPerChild. The default value is 30,
This value is too conservative for Linux systems with high stability. It can be set to 1000 or higher, and 0 to support unlimited service processing for each copy.
# Listen 3000.
# Listen 18.104.22.168: 80
# BindAddress *
The Listen parameter can be specified.
In addition to monitoring the Standard port 80, it also monitors
HTTP request. Because the FreeBSD system can have multiple IP addresses at the same time, you can also specify
Only listen to HTTP requests for a BindAddress </B> ip address. If no
Will respond to requests to all IP addresses.
Even if the BindAddress parameter is used
The HTTP daemon can only respond to requests from one IP address. However, by using the extended Listen parameter, the HTTP daemon can still respond to requests from other IP addresses. In this case, the Listen parameter is used in the same way as the second example above. This complex usage is mainly used to set up virtual hosts. The VirtualHost parameter can be used to define virtual hosts with different IP addresses. However, this method is used to set virtual hosts in the earlier HTTP 1.0 standard. Each virtual host requires an IP address, in fact, it is not very useful. In HTTP 1.1, the support for single-IP multi-domain virtual hosts is added, making the virtual host settings more meaningful.
LoadModule mime_magic_module libexec/apache/mod_mime_magic.so
LoadModule info_module libexec/apache/mod_info.so
LoadModule speling_module libexec/apache/mod_speling.so
LoadModule proxy_module libexec/apache/libproxy. so
LoadModule rewrite_module libexec/apache/mod_rewrite.so
LoadModule anon_auth_module libexec/apache/mod_auth_anon.so
LoadModule db_auth_module libexec/apache/mod_auth_db.so
LoadModule digest_module libexec/apache/mod_digest.so
LoadModule cern_meta_module libexec/apache/mod_cern_meta.so
LoadModule expires_module libexec/apache/mod_expires.so
LoadModule headers_module libexec/apache/mod_headers.so
LoadModule usertrack_module libexec/apache/mod_usertrack.so
LoadModule unique_id_module libexec/apache/mod_unique_id.so
Its Modular structure is an important feature
New functions can be added through the new module during translation. It also shows that the module can dynamically load http service processes.
It does not need to load unnecessary modules. To use the Dynamic loading Module of Apache, you only need to set the Load Module and AddModule parameters. This feature is the DSO (Dynamic Shared Object) feature of Apache, however, it is still not a simple task to make full use of the DSO feature. Modifying the settings here may cause
Cannot start normally. Therefore, if you do not want to increase or decrease
Do not change the settings here.
The above list shows the default Apache in Linux
Supported modules are actually very
Multi-module is unnecessary, and unnecessary modules are not loaded into the memory. The module can be statically connected to Apache
It can also be dynamically loaded internally to compile all Apache features into a dynamic and load-able module, which is the Port method rather than the default approach of Apache, in this way, at the expense of a small amount of performance, it brings great flexibility.
Therefore, the ability to dynamically load has a slight impact on the performance. Therefore, you can re-compile Apache and compile the required functions into Apache.
Internal, it can make the system look cleaner, and the efficiency is also slightly improved. It is not necessary to recompile Apache for this purpose only. If you need to add other features and re-compile Apache, add other modules and statically connect all modules to Apache
. Some users prefer Dynamic Loading modules.
These modules are stored in the/usr/local/apache/libexec/directory. Each module corresponds
. A detailed explanation of the functions of each module requires a considerable amount of space. The more important features will be explained in the following sections, for specific functions and usage of each module, You need to view the Apache documentation.
# ExtendedStatus On
You can use special HTTP requests to report the running status.
The ExtendedStatus parameter allows
Report more comprehensive running status information.