I. INTRODUCTION of Apache
1. What is Apache?
Apache is the world's most used Web server software. It can run on almost all widely used computer platforms and is one of the most popular Web server-side software due to its widespread use across platforms and security. It is fast, reliable, and can be augmented with simple APIs to compile perl/python and other interpreters into the server. Apache, meanwhile, is a tribe of North American Indians called Apache, in the southwestern part of the United States. Apache originates from the NCSA Server service.
1.1 Apache Applications
1 "Using Apache to run static HTML pages, pictures, (processing static files as Nginx)
2 "Using Apache combined with PHP, Perl and other programs, lamp is called the classic combination
3 "Using Apache combined with Tomcat/resin running Jsp,java and other programs, become the first choice for small and medium enterprises
4 "Using Apache as an agent. Load balancing, rewrite rule filtering, etc.
Second, Apache's compilation and installation
2. Start installing Apache software package
Apache installation is very simple, the specific operation process is as follows
2.1 Download the installation package
[[email protected]/]# mkdir-p/home/loveyu/tools[[email protected]/]# Cd/home/loveyu/tools[[email protected] tools]# wget http://mirrors.hust.edu.cn/apache[[email protected] tools]# ls-l-rw-r--r--1 root root 7684420 Jan 02:38 httpd-2. 2.32.tar.gz
2.2 Compiling and installing Apache
Compile the installation parameter description (via the command./configure-help view Apache compilation parameters)
1./configure Check that the compilation environment conforms to the compilation requirements and define which feature or feature is enabled at the time of the current program compilation and the definition of the installation path
2 "--prefix=/usr/local/apache specifies that the installation path for Apache is/usr/local/apache, and the default path is/usr/local/apache if the installation path is not specified
3 "--enable-deflate provides the content of compression transmission encoding support, general HTML,JS,CSS content of the site, using this parameter will greatly improve the transmission speed, enhance the visitor's experience
4 "--enable-expires activation allows the configuration file to control HTTP" Expires: "The amount" Cache-control "header content, and that is, the site pictures, Js,css and other content, provide client browser cache settings. This is one of the important options for Apache tuning
5 "--enable-heads provides control of HTTP request headers allowed
6 "--with-mpm-worker Select Apache MPM mode for worker mode, because the worker mode principle is more use of threads to process requests, so more concurrent requests can be processed, and system resources are less expensive than the process-based MPM Prefork ( Default to him)
7--enable-rewrite provides rewrite functionality based on URL rules. It is one of the important options for Apache tuning to convert other desired URL addresses based on a known URL address (pseudo-static function)
8 "--enable-so Activate the Apache service DSO (full name dynamic shared object) support, that is, in the future can be the DSO, the way to compile and install the shared module, the module itself cannot be compiled by DSO
[Email protected] tools]#./configure--prefix=/usr/local/apache--enable-deflate--enable-expires--enable-heads-- With-mpm-worker--enable-rewrite--enable-so[[email protected] Tools #make #执行编译命令 [[email protected] tools] #make Insta ll [[email protected] tools]# ln-s/var/local/apache//application/apache #将其做个做链接 for ease of use [[email protected] tools]# ls -ld/application/apachelrwxrwxrwx 1 root root 7 11:45 Apache--/usr/local/apache[[email protected] local]#/ap Plication/apache/bin/apachectl-l Checking the installation
/application/apache/bin/directory Apachectl is a shell script that is used to start, check, and Apache services.
2.2 Inspection and installation results
Apache does not provide the service directly after the installation, you need to start the Apache service, the specific operation is as follows
/application/apache/bin/apachectl Start[[email protected] local]# netstat-lnt #检查80端口lsof-i tcp:80 #反查80端口ps-ef |g Rep HTTP view Process entered in browser 192.168.0.102 an IT works table when Apache installation succeeds
Note: Learn to read the/application/apache/logs/error_log Apache error log in this process.
2.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 Apache Master profile/application/apache/conf/httpd.conf
[[email protected] local]# cat/application/apache/conf/httpd.conf|grep-i documentroot# documentroot:the directory out of which you'll serve Yourdocumentroot "/usr/local/apache/htdocs" to execute the default Apache site Directory # This should is changed to whatever Set DocumentRoot to.# access content that does not live under the documentroot. [[email protected] local] #cat/application/apache/htdocs/index.html
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9D/8F/wKiom1mB08HCSyt2AAF-qDjYJPg497.png "title=" Q3I3310C) k~1%2zj493r~3y.png "alt=" Wkiom1mb08hcsyt2aaf-qdjyjpg497.png "/>
2.4apache bin and Log subdirectory description
1 "bin Sub-catalogue ab #Apache HTTP server performance testing tools, easy to use, similar software has jmeter,loadrunner,webbench and other apachectl #Apache的启动命令, Apachectla is a script apxs #它是一个为Apache The HTTP server compiles and installs the extension module, which is used when the DSO mode module is compiled. This command is used when compiling the PHP software, as described later--with-apxs2=/application/apache/bin/apxshtcacheclean #这是清理磁盘缓冲区的命令, you need to specify the relevant parameters at compile time, and seldom use htpasswd #建立和更新基本认证文件, for example, httpd #httpd为apache的控制命令 is used when configuring monitoring services such as Nagios. You can also use Apachect to perform httpdrotatelogs #apache own log polling commands, but you can also use the old boy's work scene to have cronolog alternative 2 "Logs subdirectory ( This is the Apache default log path including the error log as the access log) access_log #这是Apache的默认访问日志文件, using tail -f access.log can view site user access information error_log #这是Apache的错误日志文件, if Apache has a startup failure and other issues, be sure to look at this file httpd.pid #这是httpd的pid文件, when the HTTP process starts, the ID number of all processes is written to this file [[Email protected] apache]# ps -ef |grep httpd|grep -v greproot 28666 1 0 11:56 ? 00:00:00 /usr/local/apache/bin/httpd -k startdaemon 28667 28666 0 11:56 ? 00:00:00 /usr/local/apache/bin/httpd -k startdaemon 28668 28666 0 11:56 ? 00:00:00 /usr/local/apache/bin/httpd -k startdaemon 28669 28666 0 11:56 ? 00:00:00 /usr/local/apache/bin/httpd -k startdaemon 28670 28666 0 11:56 ? 00:00:00 /usr/local/apache/bin/httpd -k startdaemon 28671 28666 0 11:56 ? 00:00:00 /usr/local/apache/bin/httpd -k startdaemon 28727 28666 0 12:02 ? 00:00:00 /usr/local/apache/bin/httpd -k start[[email protected] apache]# cat logs/ httpd.pid 286663 "Modules apache module directory, such as PHP,MEMCACEH and other modules are compiled here
2.5Apache extension File
The Apache extension configuration file is implemented by embedding the include command in the httpd.conf Master profile, but by default the comment State excerpt http.conf part of the include line in the main configuration file, as shown below; # Virtual hosts# Include conf/extra/httpd-vhosts.conf If you cancel the # number in front of this line, it means that the configuration of the virtual host is turned on, that is, load conf/extra/httpd-vhosts.conf# Local access to the Apache HTTP Server manual#include conf/extra/httpd-manual.conf# Distributed Authoring and Versioning (WebDAV) #Include Conf/extra/httpd-dav.conf
[Email protected] conf]# tree-l 2/application/apache/conf/extra//application/apache/conf/extra/├── Httpd-autoindex.conf├──httpd-dav.conf├──httpd-default.conf #这个文件配置的是Apache的相关服务参数, such as timeout time, maintain connection time, etc. ├── httpd-info.conf├──httpd-languages.conf #语言支持配置 ├──httpd-manual.conf├──httpd-mpm.conf #服务器池管理, which is a configuration file optimized for Apache, If you choose Apache mode and configure the number of connections, the common mode is worker mode and profork mode ├──httpd-multilang-errordoc.conf├──httpd-ssl.conf #提供Apache SSL support configuration file ├──httpd-userdir.conf└──httpd-vhosts.conf #这是虚拟主机的配置文件
Configuration of 2.6Apache Virtual host
2.6.1 Domain-based virtual host combat configuration
1 "Open config file httpd.conf contains httpd-vhosts.conf file configuration
Use the VI command to edit the Apache master configuration file httpd.conf. Specific steps: [[email protected] loveyu]# Cd/application/apache/conf/[[email protected] conf]# CP httpd.conf Httpd.conf.loveyu.20170511[[email protected] conf]# VI httpd.conf404 # Virtual hosts405 Include conf/extra/ httpd-vhosts.conf# cancel the "#" number equals the configuration of the open virtual host
2 "Configure the virtual host (if the default virtual host configuration does not delete, restart Apache will report syntax errors) into the virtual host configuration file, edit the virtual host Profile VI httpd-vhosts.conf specific operations as follows
[[email protected]/]# Cd/application/apache/conf/extra/[[email protected] extra]# CP httpd-vhosts.conf Httpd-vhosts.conf.loveyu.20170511[[email protected] extra]# grep-v \# httpd-vhosts.confnamevirtualhost *:80< VirtualHost *:80>serveradmin [Email protected]documentroot "/var/blog" # (this Site directory must exist or will be error) ServerName Blog.feitianxihuanni.orgServerAliasfeitain.orgErrorLog "Logs/blog-error_log" Customlog "Logs/blog-access_log" Common</virtualhost>[[email protected] extra]# mkdir/var/blog-p# Check syntax error: [[email protected] extra]#. /.. /bin/apachectl-tsyntax OK
3 "Set up the Site Directory and home page of the virtual host index.html (for testing)
[Email protected] extra]# mkdir/var/blog-p
[[email protected] extra]# chown-r apache.apache/var/blog give permission, this directory is the future release program. The authorization here is very important, this command is not the most secure configuration, the more optimized Site Directory permissions control method, see the following text Optimization Apache section, for this section can not be executed
[Email protected] extra]#. /.. /bin/apachectl Graceful Restart Apache service
#提示: Here is the graceful parameter, graceful represents graceful restart, this parameter can be restarted is to make the user who is browsing do not feel, will not forcibly interrupt the user's access parameters, but after processing completed the request in the restart
4 "Edit the Hosts file on our laptop to add the following:
The common path of the Hosts file is: C:\windows\system32\drivers\etc,hosts file is the local DNS resolution file, its function is to resolve the specified domain name to the corresponding IP, multiple domain names corresponding to an IP, By default, the configuration resolution in the Hosts file takes precedence over the DNS server.
192.168.0.102Www.feitian.com added to the Hosts file, the following is the virtual host configuration file, add the extension module, in the following blog we will introduce.
[[email protected] extra]# egrep -v "^#|^$" Httpd-vhosts.confnamevirtualhost *:80<virtualhost *:80> serveradmin [email protected] DocumentRoot "/var/blog" Servername www.feitian.com serveraliasfeitian.com errorlog "Logs/blog-error_log" # CustomLog "Logs/blog-access_log" common customlog "|/usr/local/sbin/cronolog /var/logs/access_www_%w.log" combinedExpiresActive OnExpiresDefault "Access plus 12 month" Expiresbytype text/css "Now plus 12 month" expiresbytype image/jpeg "Access plus 12 months "expiresbytype image/x-icon " Access plus 2 months "ExpiresByType text/javascript "Access plus 12 month"expiresbytype image/gif " Access plus 12 month "expiresbytype image/jpg " Access plus 12 mont "expiresbytype image/png " Access plus 12 mont " expiresbytype application/x-shockwave-flash "Access plus 12 month" ExpiresByType video/x-flv "Access plus 12 month" <ifmodule mod_deflate.c> addoutputfilterbytype deflatetext/html text/plain text/css text/javascript text/cssAddOutputFilterByType DEFLATEapplication/x-httpd-phpAddOutputFilterByType Deflateapplication/x-javascriptaddoutputfilter deflate js cssdeflatecompressionlevel 6 SetOutputFilter DEFLATE </ifmodule> </VirtualHost>
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/9D/A3/wKiom1mDAwqBdDbnAAIeMArH8jA228.png "title=") Jkk42vurqgeacdzc3[aiua.png "alt=" Wkiom1mdawqbddbnaaiemarh8ja228.png "/>
The following is the index.html file in the site Directory
[[email protected] extra]# ll/var/blog/total 4-rw-r--r--1 root root 161 3 18:50 Index.html[[email protected] extra] # cat/var/blog/index.html
This article is from the "13122323" blog, please be sure to keep this source http://13132323.blog.51cto.com/13122323/1953402
Apache Compilation Installation 2.2