Features of Apahce
Powerful, simple configuration, fast, wide application, stable and reliable performance, and can be used as proxy server or load balancer
Application scenarios.
Use Apache to run static HTML Web pages, pictures (processing static small file ability is less than nginx);
Using Apache in conjunction with the PHP engine to run PHP, Perl and other programs, lamp is called the classic combination;
Using Apache combined with Tomcat, resin running Jsp,java and other programs, become the first choice for small and medium enterprises;
Use Apache for proxies, load balancing, rewrite rules filtering, and more.
installation of Apache :
Version: Apache 2.2.2
System environment: CentOS 5.8
1.1, check whether the system installs Apache, if any, uninstall:
Inquire:
Rpm-aq httpd* to see if the Apache server is installed
Q equals query queries
A equals all
Unloading:
Rpm-e-nodeps http-2.2.2 .....
e equivalent to-erase means remove
nodeps English explanation for dont do a depentdency check does not do the dependency checking between software
Note that in the CentOS6.5 version, use yum remove apache*-y to uninstall
1.2. Installing Apache
(Good habits) create a directory:
Mkdir/home/qingcong/tools
Cd/home/qingcong/tools
(I'm used to putting my own software installation package under the tools in my home directory)
1.2.1, Download:
If connected, use wget http//To get packages and keys
If there is no Internet connection, you can download the apache2.2.3 and key (verify file) on the official website, then upload to the tools directory with Rz-y.
1.2.2, installation method is installed by compiling:
TAR-ZXVF Httpd-2.2.22.tar extract to current directory
CD httpd-2.2.22
Compiler
./configure \
--prefix=/application/apache2.2.22 \
--enable-deflate \
--enable-expires \
--enable-headers \
--enable-modules=most \
--with-mpm=worker \
--enable-rewrite \
--enable-so
Description of the parameters after the./configure
--prefix=/application/apache2.2.22 indicates the path of the specified installation, if not specified, the default is [/usr/local/apache2]
--enable-deflate provides the content of compressed transmission encoding support, general HTML,JS,CSS and other content of the site, the use of this parameter function will greatly improve the transmission speed, improve the visitor access experience. In a production environment, this is one of the important options for Apache tuning.
--enable-expires activation allows the configuration file to control HTTP "Expires:" and "Cache-control:" header content, that is, Web site pictures, JS, CSS and other content, to provide in the client browser cache settings. This is one of the important options for Apache tuning
The--enable-headers provides control of the HTTP request header that is allowed.
--with-mpm=worker chooses the Apache MPM mode as worker mode, because the worker mode principle is that more threads are used to process requests, so more concurrent requests can be processed, and system resources are less expensive than the process-based MPM Prefork. If you do not specify this parameter, the default mode is Prefork process mode. This is one of the important options for Apache tuning
--enable-rewrite provides rewrite functionality based on URL rules. Convert to another desired URL based on a known URL. such as the pseudo-static function of the Web page is the implementation of this module. This is an important feature that is used in Apache production environments.
--ENABLE-SO activation of the Apache service DSO (full dynamic shared object) support, that is, in the future can be the DSO to compile the installation of the shared module, the module itself can not be compiled by DSO.
In the compilation process, the last line error:
Checking whether to enable Mod_deflate ... configure:error:mod_deflate have been requested but can not is built due to pre Requisite failures
Need to install Devel
Yum install Devel from Yum source
can also be the RZ upload, manually installed RPM-IVH zlib-devel-1.2.3-29.el6.x86_64.rpm.
[[Email protected]]# make
#执行编译命令
[[Email protected]]# make install
#执行安装命令
[Email protected]]# ln-s/application/apache2.2.22/application/apache
#此条命令为创建软连接, the meaning is very significant. This is the experience of the production environment.
To change the Apache installation path via soft link to/application/apache convenient for human use, when the Apache software upgrade to the new version, delete the original soft link to re-establish a new to the/application/apache soft link is good, In other programs where there is a reference to the Apache path, no changes are required
To view Apache installation conditions:
/application/apache/bin/apachectl-l
To start the Apache service:
/application/apache/bin/apachectl start
Check the startup situation:
Computer Browser input in this network segment: http://192.168.31.140 show it Works is normal (note that the URL is the IP address of the service, installed on the virtual machine is the virtual machine's IP address)
If you do not come out of the It works content, check the following, in turn:
1, iptables and SELinux are closed:
2. Check if httpd port 80 is present:
Netstat-lnt|grep 80
3, check whether the httpd process exists
Ps-ef|grep httpd
4, the server local wget http://192.168.31.140 test
Note: If 2/3 does not meet the requirements, that 4 will not have to check, certainly not, direct 5.
Server local wget test, skip firewall interference directly to check HTTP service
5. Check the Apache error log to see if there are any exceptions:
Tail-200/application/apache/log/error_log
1.3 Deployment of a simple Web site
Apache's default Site directory is the/application/apache/htdocs in the installation directory, which can be found in the main profile/appilcation/apache/conf/httpd.conf: grep-i DocumentRoot httpd.conf
At this point, if you want to deploy Web services, you just need to put all the developed programs under Htdocs.
Configuring Apache Domain-based virtual hosts
1. Open the configuration containing the httpd.conf file in the master profile
Include conf/extra/httpd-vhosts.conf (Original # comment, remove # can)
2. Configure httpd-vhosts.conf
Vi/application/apache/conf/extra/httpd-vhost.conf
<virtualhost *:80>
ServerAdmin [email protected]
DocumentRoot "/data/www/blog"
ServerName blog.etiantian.org
Serveralias etiantia.org
Errorlog "Logs/blog-error_log"
Customlog "Logs/blog-access_log" common
</VirtualHost>
Configuring the Httpd.conf File
Add Site Directory permissions, otherwise 403 error is reported
<directory "/data/www/blog" >
AllowOverride None
Options None
Order Allow,deny
Allow from all
</Directory>
3. Check for syntax errors
/application/apache/bin/apachectl-t
4. Restart the Apache service:
/application/apache/bin/apachectl Graceful
Note: Graceful is used here instead of the restart parameter, graceful represents an elegant reboot, which allows the user to be unaware when restarting, that is, restarting without forcing the end user's access request, but after processing and then restarting. The graceful is very heavy in the production environment.
Reboot, check it out.
Configure Apache IP-based virtual hosts (rarely used in production environments)
1. Increase the virtual IP
Ifconfig eth0:201 192.168.3.201 up
(Delete: Ifconfig eth0:201 192.168.3.201 down)
2. Modify extra inside Httpd-vhost.conf file
<virtualhost 192.168.3.201:80>
ServerAdmin [email protected]
DocumentRoot "/data/www/bbs"
ServerName 192.168.3.201
Serveralias etiantia.org
Errorlog "Logs/bbs-error_log"
Customlog "Logs/bbs-access_log" common
</VirtualHost>
3. Check for syntax errors
/application/apache/bin/apachectl-t
4. Restart the Apache service:
/application/apache/bin/apachectl Graceful
Note: Graceful is used here instead of the restart parameter, graceful represents an elegant reboot, which allows the user to be unaware when restarting, that is, restarting without forcing the end user's access request, but after processing and then restarting. The graceful is very heavy in the production environment.
Reboot, check it out.
Configure Apache virtual hosts based on different ports
1. Modify the httpd-conf file under the Conf file to increase the port
Listen 8091
Listen 8092
2. Modify extra inside Httpd-vhost.conf file
<virtualhost *:8091>
ServerAdmin [email protected]
DocumentRoot "/data/www/bbs"
ServerName 192.168.3.201
Serveralias etiantia.org
Errorlog "Logs/bbs-error_log"
Customlog "Logs/bbs-access_log" common
</VirtualHost>
3. Check for syntax errors
/application/apache/bin/apachectl-t
4. Restart the Apache service:
/application/apache/bin/apachectl Graceful
Note: Graceful is used here instead of the restart parameter, graceful represents an elegant reboot, which allows the user to be unaware when restarting, that is, restarting without forcing the end user's access request, but after processing and then restarting. The graceful is very heavy in the production environment.
Reboot, check it out.
Expires_modules (client browser access cache, one of the Apache tuning items)
Installation:
1. Compile and install Apache when adding--enable-expires
2.DOS compile and install into Apache:
First go to Apache extracted files:
[Email protected] metadata]# cd/home/oldboy/tools/httpd-2.2.22/modules/metadata/
[email protected] metadata]# ll MOD_EXPIRES.C
-rw-r--r--. 1 18285 Nov MOD_EXPIRES.C
Installation:
[Email protected] metadata]#/application/apache/bin/apxs-c-i-a mod_exipres.so
Check:
[Email protected] metadata]# ll/application/apache/modules/mod_expires.so
-rwxr-xr-x. 1 root root 37398 Apr 16:34/application/apache/modules/mod_expires.so
Application:
Append the following to the end of the conf/httpd_conf file, all virtual hosts and Htdocs are valid
ExpiresDefault "Access plus month"
Expiresbytype text/html "Access plus months"
Expiresbytype text/css "Access plus months"
Expiresbytype image/gif "Access plus months"
Expiresbytype image/jpeg "Access plus months"
Expiresbytype image/jpg "Access plus months"
Expiresbytype image/png "Access plus months"
Expiresbytype Application/x-shockwave-flash "Access plus months"
Expiresbytype application/x-javascript "Access plus months"
Expiresbytype video/x-flv "Access plus months"
Append in conf/extra/httpd-vhosts.conf, all virtual hosts are in effect
Add in <VirtualHost> inside conf/extra/httpd-vhosts.conf, then the corresponding virtual host is in effect
Mod_deflate (compression transfer, one of Apache tuning)
The following is appended to the httpd_conf tail, and all virtual hosts and htdocs are in effect
<ifmodule mod_deflate.c>
Deflatecompressionlevel 9
Setoutputfiler DEFLATE
Addoutputfilterbytype DEFLATE text/html Text/plain text/xml
Addoutputfilterbytype DEFLATE Application/javascript
Addoutputfilterbytype DEFLATE Text/css
</ifmodule>
This article from "Pillow with the Tao" blog, declined reprint!
Installation and configuration of Apache