1. Introduction
In the first article, we integrated Apache + Tomcat and used apache to parse static files and decompress them for Tomcat. However, the test server finds that the performance of the two is insufficient and the server performance cannot be fully utilized. This article will improve the performance of Apache.
The optimization here is for the Windows platform, and the Linux Apache optimization will be discussed later.
2. Apache optimization 2.1 Remove unused modules
Apache is quite powerful, but not all of its functions can be used in every project. It loads some modules that we usually don't use, which is actually unnecessary.
The method for removing unnecessary modules is very simple. Use # To comment out httpd. for the modules loaded under the conf file, remember to test configuration for the annotation loading module. Otherwise, you will not know where to start when you get on a wrong business trip. usually remove
The modules include mod_include.so and mod_autoindex.so. You can try them on your own. Of course, this operation is not executed when the performance is running.
2.2 set thread parameters
In the httpd. conf configuration, find # loadmodule vhost_alias_module modules/mod_vhost_alias.so and add the following content:
<IfModule mpm_winnt_module> ThreadsPerChild 300 MaxRequestsPerChild 3000</IfModule>
★Threadsperchild: Maximum number of threads owned by a process range [100-500]
★Maxrequestsperchild: the maximum number of connections that a thread can accept. The default value 0 may cause memory leakage. Apache has a polling mechanism and is automatically adjusted.
2.3 start Apache output Compression
Load the mod_deflate.so module and remove #
LoadModule deflate_module modules/mod_deflate.so
Then, append the following configuration after <ifmodule mpm_winnt_module>... </ifmodule>:
<IfModule mod_deflate.c> DeflateCompressionLevel 6 AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php AddOutputFilter DEFLATE js css</IfModule>
2.4 Security deny
Deny is used to prohibit access to several files (improving security). The usage is as follows:
2.5 Security Protection Against DoS Attacks
Mod_dosevasive22.dll can prevent DoS attacks on webpages on the network (for example, robots constantly refresh specified webpages and access them ). Download the DLL file and place it in modules. Modify the httpd. conf file.
Append the following file at the end of the file:
LoadModule dosevasive22_module modules/mod_dosevasive22.dllDOSHashTableSize 3000DOSPageCount 3DOSSiteCount 50DOSPageInterval 1DOSSiteInterval 1DOSBlockingPeriod 10
Where:
★Doshashtablesize 3000 total blacklists
★The dospagecount page is regarded as a DoS attack when the number of attacks is set to this value.
★Dossitecount is determined as a DoS attack when the number of attacks on the site is set to this value.
★Dospageinterval page read Interval
★Dossiteinterval
★Dosblockingperiod
Time unit: seconds
Close Apache after configuration and start
Start Tomcat configured in the first article and access http: // localhost/webdemo/to obtain
Press F5 to refresh the page.
Access continues in 10 seconds.
2.6 modify default configuration parameters
Search for the httpd-default.conf in httpd. conf and release its configuration
Include conf/extra/httpd-default.conf
The default configuration parameters for Apache exist in this file.
## Timeout: The number of seconds before receives and sends time out.#Timeout 300## KeepAlive: Whether or not to allow persistent connections (more than# one request per connection). Set to "Off" to deactivate.#KeepAlive On
Keepalive: Indicates whether to maintain a TCP connection after the user request is complete;
On: indicates that a TCP connection with the server is maintained when the request is complete. If there are still requests, the connection is completed. You do not need to repeat the connection, the timeout time (MS) set above during maintenance)
Off: the connection is closed immediately after the request is complete.
Differences:
On: more memory is required, but the access speed is improved. We recommend that you enable this function when there are many JS, CSS, and IMG images on the page.
Off: it consumes less memory. We recommend that you set it to off every time the page is dynamically generated by the app server.
## MaxKeepAliveRequests: The maximum number of requests to allow# during a persistent connection. Set to 0 to allow an unlimited amount.# We recommend you leave this number high, for maximum performance.#MaxKeepAliveRequests 100## KeepAliveTimeout: Number of seconds to wait for the next request from the# same client on the same connection.#KeepAliveTimeout 5
Do not set maxkeepaliverequests to 0 (0 is unlimited), which may easily lead to memory exceptions. You can adjust the server performance when the server performance is high. We recommend that you keep the default value.
Comment accessfilename
#AccessFileName .htaccess
Serversignature is set to off to prevent the server from broadcasting sensitive information. The default value is on.
Set hostnamelookups to on to reduce the number of DNS queries.
2.7 listening port
By default, the Apache listener is port 80. In practice, it is best to specify the IP address corresponding to the listener's specific application: 80:
Listen XXX. XXX. XXX (specific IP address): 80
Because the server may have multiple IP addresses, this will put the server upside down and reduce security. This situation should be rare.
2.8 Associate Computer Office software
In applications, you often need to open or download attachments, such as Word and Excel, which can be opened by setting the key to the local office software.
Append after addtype application/X-gzip. GZ. tgz
AddType application/vnd.openxmlformats docx pptx xlsx doc xls ppt txt
2.9 clear comments
This is the simplest operation, with no technical content. delete all the comments in the httpd. conf file to keep a "pure" configuration...
This article ends here!
Note: The performance optimization should be verified through actual operations. It cannot be taken for granted. What is the only criterion for testing truth...
Article 3 Optimization Path Apache Optimization