Apache2 Optimization Configuration Summary

Source: Internet
Author: User

Apache2 Optimization Configuration Summary
 

Apache2 Optimization Configuration Summary
Running and testing environments

Ubuntu server 12.04 LTS

Configuration Parameter Adjustment

The configuration files are usually stored in the configuration parameters under apache2.conf conf. d/secrity default. conf under/etc/apache2 /.

1. hostnamelookups off

Enabling Domain Name Search increases the burden on the AP. We recommend that you disable it to slow down access.

2. sethandler server-status

Disable this operation or expose the information.

3. allowoverride none

If you do not need. htaccess and do not need to override any pseudo-static data, set none or All.

4. option-indexes

This is to prohibit directory structure exposure.

5. timeout 5

Recommendation 5: The AP accepts the request or disconnects the request after the corresponding time.

6. keepalive on

This must be enabled because HTTP 1.1 supports enabling persistent connections to reduce the number of resource files requested by the AP each time. This increases the efficiency of restarting the process.

7. maxkeepaliverequests 50

Maximum number of persistent connections

8. keepalivetimeout 5

If the persistent connection does not respond after more than 5 seconds, the value cannot be too large because you have been wasting system resources.

9. servertokens

The information contained in the response header. This setting is servertokens Prod.

10. serversignature off

This is the server information when the 404 page is generated .. if it is set to off, only Apache will be displayed and no version information will be displayed.

11. MPM

The key factor is the main factor affecting the concurrency efficiency.

Generally, the prefork mode is used after Ubuntu is installed by default. If you want to use the work mode, set the configuration file during compilation.

The following explains that the prefork mode is relatively secure for starting processes. When a request is suspended, it will not affect other processes.

Below is my configuration

 

 

<IfModule mpm_prefork_module>
ServerLimit 1000
StartServers 10
MinSpareServers 30
MaxSpareServers 45
MaxClients 1000
MaxRequestsPerChild 3000
</IfModule>

The first ServerLimit is required... because the default MaxClients 256 is the maximum. You must add limit to increase the maximum service volume.

StartServers 10 enabled AP count

MinSpareServers 30 min idle Process

MaxSpareServers 45 maximum number of idle processes. These two processes must be adjusted based on the server load and service volume.

MaxClients 1000 maximum service volume at the same time, this is more critical... if the website concurrency is relatively large, please increase this number, but note that if it is too large, the physical memory will crash

MaxRequestsPerChild 3000 maximum number of sub-Processes

The number configured above is the best for my personal machine. Please use AB or jmeter based on your actual situation, and then use top observation to adjust the number to the most suitable one.

Enable deflate

Send the following three modules ln-s to mod-enable.

Mod_deflate.so mod_expires.so mod_header.so

Then add

 

<Ifmodule mod_deflate.c> AddOutputFilterByType DEFLATE text/html text/plain text/css application/x-httpd-php text/javascript application/x-javascript text/cssAddOutputFilter DEFLATE js css # compress js, css file # Don't compress images # Do not compress the photo file. SetEnvIfNoCase Request_URI (?: Gif | jpe? G | png) $ no-gzip dont-varySetEnvIfNoCase Request_URI (?: Exe | t? Gz | zip | bz2 | sit | rar) $ no-gzip dont-varySetEnvIfNoCase Request_URI. pdf $ no-gzip dont-vary # SetEnvIfNoCase Request_URI. (css | js) $ no-gzip dont-vary # Make sure proxies don't deliver the wrong contentHeader append Vary User-Agent env =! Dont-Example 6 SetOutputFilter DEFLATE </ifmodule> <IfModule details> ExpiresActive OnExpiresByType text/css "now plus 1 month" ExpiresByType application/x-javascript "now plus 5 day" ExpiresByType image/ jpeg "access plus 1 month" ExpiresByType image/gif "access plus 1 month" ExpiresByType image/bmp "access plus 1 month" ExpiresByType image/x-icon "access plus 1 month" ExpiresByType image/png "access plus 1 month" ExpiresByType application/x-shockwave-flash "access plus 1 month" </IfModule>

After GZIP is enabled, the transmission content is compressed. Therefore, the speed is faster and the bandwidth is reduced.

 

After the above configuration, I used AB to test and improve the performance...

 


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.