Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
Copyright NOTICE: You can reprint, reprint, please be sure to hyperlink form to indicate the original source of the article and author information and this statement
Apache is a long and powerful Web server, but its rich features don't always know where to start for a novice. I personally feel that Apache design fully embodies the advantages of modular design, through the dynamic module loading (DSO) mode of installation, any child application module can be modified by the simple configuration file building block-type flexible configuration. The installation process can start with a simple static HTML service, a module for learning to use. From simple HTML static services (core) to complex dynamic page services (core + PHP, core + resin, core + PHP + mod_gzip, core + resin + mod_expire).
This paper introduces the planning of Web services, httpd installation/Application module configuration, upgrade/maintenance, and so on, from the angle of simplifying the installation ==> performance Tuning ==> maintenance convenience. Let the Apache and Php,resin application modules such as independent upgrades, completely unrelated.
Web application Capacity Planning: The planning of Web services and some simple estimating formulae based on the characteristics of hardware configuration and Web application;
Apache installation process: Apache's General simplified installation option, convenient for later application of the modular configuration;
#define HARD_SERVER_LIMIT 2560 <=== Add a "0" to the back of the original Hard_server_limit 256.
Optional Application module/tool Installation: PHP resin mod_gzip mod_expire and the coordination between the modules;
Mod_gzip Installation: Modify the APXS path in makefile: then make make install
Tools: Log Wheel tool Cronolog installation: http://www.cronolog.org
Upgrade/maintenance: See how the common and modular installation process simplifies the daily upgrade/maintenance effort;
According to the above method: the responsibilities of the system administrator and the application administrator can be clearly separated and independent.
System installation: The responsibility of the system administrator is to install a DSO mode of Apache, and then Colon can,
Application installation: The application Administrator is responsible for the specific application of the required modules, such as PHP resin, and set up httpd.conf in the relevant configuration.
System Upgrade: System administrator: Upgrade OS/upgrade Apache
Application Upgrade: Application Manager: Upgrade application module, PHP resin, etc.
Capacity Planning for Web applications
Apache is primarily a memory-consuming service application, my personal summary of the empirical formula:
Apache_max_process_with_good_perfermance < (total_hardware_memory/apache_memory_per_process) * 2
apache_max_process = apache_max_process_with_good_perfermance * 1.5
Why would there be a apache_max_process_with_good_perfermance and apache_max_process? The reason is that the system can use more memory for file system caching at low load, thus further increasing the response speed of individual requests. Under high load, the system's single request response speed will be slow, but more than apache_max_process, the system will reduce the efficiency of the system because it starts using the hard disk to do the virtual memory swap space. In addition, the same service: The apache_max_process of 2G memory machines is typically set to only 1.7 times times that of 1G memory, because Apache itself can degrade performance because of too much process.
An Apache + mod_php server: An Apache process typically requires 4 m of memory
So on a 1G memory machine: Apache_max_process_with_good_perfermance < (1g/4m) * 2 = 500
apache_max_process = 500 * 1.5 = 750
So plan your application so that the service runs as far as 500 processes below to maintain a higher efficiency and set Apache's soft limit at 800.
An Apache + mod_resin server: An Apache process typically requires 2 m of memory
On a 2G memory machine:
Apache_max_process_with_good_perfermance < (2g/2m) * 2 = 2000
apache_max_process = 2000 * 1.5 = 3000
The above estimates are based on small file services (one request is typically below 20k). For file download type sites, you may also be affected by other factors such as bandwidth.
Apache installation process
The hard upper limit of the number of servers Hard_server_limit modification:
The default maximum number of processes in Apache source code is 256, and needs to be modified Apache_1.3.xx/src/include/httpd.h
#define HARD_SERVER_LIMIT 1024
#elif defined (NETWARE)
#define HARD_SERVER_LIMIT 2048
#define HARD_SERVER_LIMIT 2560 <=== Add a "0" to the back of the original Hard_server_limit 256.
The default maximum number of users in Apache is 256: This is a very good default setting for server memory or about 256M, but as the cost of memory drops dramatically, the server memory configuration of a large site now is generally a higher order of magnitude than it was then. So the hard limit of 256 processes is too wasteful for a 1G ram machine, and Apache's soft upper limit max_client is limited to hard_server_limit, so if the Web server has more than 256M memory, you should increase the Apache Hard_server_limit. Based on personal experience: 2560 has been able to meet the capacity planning of most servers less than 2G of memory (Apache's soft limit planning please look back).
Apache compilation: The following generic compilation options are available to meet any future installation of the module
--prefix=/another_driver/apache/: It is recommended that the Apache service be installed on another drive device, so that the hard disk is often the lowest-life device for the system, so that a complete separation of service data and systems will not only improve the speed of data access, More importantly, greatly facilitates system upgrades, applying backup and recovery processes.
--shared-module=max: Loading a child module with dynamic loading will result in 5% performance degradation, but it is nothing compared to the convenience of configuration: For example, the module upgrades conveniently, the system upgrades the risk to reduce, the installation process standardization and so on
--enable-module=most: Most can be used to compile some of the less commonly used modules, such as the Mod_expire described later, is not in the default common Apache module
If you don't want to build so, you can do this:
But the result will be found that such a compilation of service performance can only slightly improve (5% or so), but lost the future system upgrades and module upgrade flexibility, whether the module or Apache itself upgrade must be the Apache and PHP source added together recompile.
The default configuration file for Apache is generally larger: you can use the method of removing annotations to streamline: And then go into the specific implant process to get you to customize what you need more quickly.
Grep-v "#" Httpd.conf.default >httpd.conf
There are several common items that need to be modified:
#服务端口, the default is 8080, it is recommended to adjust the entire Apache configuration and then change the service port to the official service port
Port 8080 => 80
#服务器名: No default
#最大服务进程数: Based on service capacity forecast settings
MaxClients 256 => 800
#缺省启动服务后的服务进程数: When the service is more stable, the httpd number can be set according to the average load
Startservers 5 => 200
Do not modify:
Previous suggestions were made to modify:
Minspareservers 5 => 100
Maxspareservers => 200
But from my experience, the defaults are already very optimized, and it's nice to have Apache adjust the number of child-sharing processes themselves.
On Solaris or some applications that are more vulnerable to memory leaks:
Maxrequestsperchild 0 =>3000
Installation configuration for application modules and tools:
Because of the use of module dynamic loading mode, so you can easily through simple configuration adjustment to make the Apache you need: It is best to eliminate the most common modules (whether in safety or efficiency).
For example: for static page Server: On what other sub modules are not loaded, PHP application plus PHP module, for Java application on the resin module load. and the various modules of the plug is very simple, so the debugging process can be simply by commenting out the unwanted modules, without recompiling.
Generally, modules that are not required include:
#LoadModule Env_module libexec/mod_env.so
#LoadModule Negotiation_module libexec/mod_negotiation.so
#LoadModule Status_module libexec/mod_status.so
#server side include is obsolete.
#LoadModule Includes_module libexec/mod_include.so
#LoadModule Autoindex_module libexec/mod_autoindex.so
#尽量不使用CGI: It's always been the best place for Apache security.
#LoadModule Cgi_module libexec/mod_cgi.so
#LoadModule Asis_module libexec/mod_asis.so
#LoadModule Imap_module libexec/mod_imap.so
#LoadModule Action_module libexec/mod_actions.so
#LoadModule Access_module libexec/mod_access.so
#LoadModule Auth_module libexec/mod_auth.so
#LoadModule Setenvif_module libexec/mod_setenvif.so
The best reservations are:
LoadModule Config_log_module libexec/mod_log_config.so
LoadModule Mime_module libexec/mod_mime.so
#用于缺省index文件: index.php etc.
LoadModule Dir_module libexec/mod_dir.so
Available for use are:
#比如: You need to debug PHP under ~/username/to
LoadModule Userdir_module libexec/mod_userdir.so
#比如: A previous URL needs to be turned on or a CGI Script-alias is required
LoadModule Alias_module libexec/mod_alias.so
The most commonly used may be the front-end of PHP and Java application Server, in addition, from the performance of the use of mod_gzip can reduce the flow of about 40%, reduce the machine for transmission load, and mod_expires can reduce about 10% of duplicate requests, Lets duplicate users cache the specified page request results locally and do not issue a request to the server at all.
It is recommended that all module configurations be placed within the configuration of the corresponding modules: <ifmodule some_module.c>some_module config </IfModule>
Installation of PHP:
Configurations that need to be modified:
AddType application/x-httpd-php. php. php3. any_file_in_php
Installation settings for resin:
The specific resin settings are placed in another file: for example,/home/resin/conf/resin.conf
Installation configuration for Mod_expires:
Expiresbytype image/gif "Access plus 1 month"
Expiresbytype text/css "now plus 1 month"
ExpiresDefault "now plus 1 day"
All. gif files expire after 1 months
All files expire 1 days after default
Installation of Mod_gzip
Round robin of logs: Installation and setup of Cronolog
Cronolog can be very neat to store logs on a day-round basis
The default compilation is installed under/usr/local/bin/, just to change the configuration to:
Since the use of dynamic Module loading mode (DSO mode) to install Apache,apache httpd Core Services and application modules and application modules have become very flexible, we recommend that all the Independent module configuration
, this configuration is very easy to adjust by masking a module: for example:
It shields the mod_gzip, while the other modules do not have any effect.
Installation and maintenance process:
System installation: System Administrator's responsibility is to install the system and a according to the DSO mode installed Apache, and then colon.
Application installation: The application Administrator is responsible for the specific application of the required modules and set the httpd.
System Upgrade: System Administrator: Upgrade the system/upgrade Apache
Application Upgrades: Application Manager: Upgrade application modules: PHP Caucho, etc.
System backup/restore: If Apache is not on the default system disk, just want to backup the Apache directory, encounter system partition hardware problems directly using a prepared system colon, and then directly to the physical disk of Apache recovery on the line.
System administrator: Apache's most simplified installation OS + Apache (httpd core only)
Application Administrator: Application module to customize the Pure static page service
PHP Dynamic page
Application Example: www.example.com
Example: Standalone upgrades for Apache and PHP modules.
If Apache is installed in the following ways:
PHP is installed in the following ways:
When you upgrade Apache alone later, you are still:
When you upgrade PHP individually, you are still:
Web acceleration based on anti-phase proxies:
Squid and mod_proxy can be reversed-phase agent acceleration. and caching based agent acceleration than the original Web services, speed will be a number of levels of ascension.
After Apache installation, there are no but 2 files that are useful in the default root directory:
Favicon.ico:favicon.ico is a 16x16 site icon file, if the browser found this file, in the address bar will use this icon to replace the browser page icon. This feature is supported by mainstream browsers such as IE6 and Mozilla.
For example: Http://www.chedong.com/favicon.ico
Robots.txt: A crawler (spider) website that tells search engines that pages can be indexed and those that can't.
For specific instructions please refer to: http://www.robotstxt.org/wc/robots.html
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to firstname.lastname@example.org. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.