httpd-2.4:
新特性:
(1) MPM支持运行为DSO机制;以模块形式按需加载;
(2) event MPM生产环境可用;
(3) 异步读写机制;
(4) 支持每模块及每目录的单独日志级别定义;
(5) 每请求相关的专用配置;
(6) 增强版的表达式分析式;
(7) 毫秒级持久连接时长定义;
(8) 基于FQDN的虚拟主机也不再需要NameVirutalHost指令;
(9) 新指令,AllowOverrideList;
(10) 支持用户自定义变量;
(11) 更低的内存消耗;
新模块:
(1) mod_proxy_fcgi
(2) mod_proxy_scgi
(3) mod_remoteip
CentOS 6编译安装httpd-2.4:
在CentOS 6中使用httpd-2.2依赖于apr-1.4+,apr-util-1.3.9
编译安装步骤:
(1)安装编译开发环境包组: Development tools Server Platform Development pcre-devel
(2)关闭http-2.2并关闭开机启动,防止覆盖此版本。
[[email protected] ~]# service httpd stop Stopping httpd: [ OK ] [[email protected] ~]# chkconfig httpd off
(3)编译安装apr-1.5.0和apr-util-1.5.3
[[email protected] apr-1.5.0]# ./configure --prefix=/usr/local/apr #apr-util依赖于apr所先编译安装apr,并指定一个不同与系统默认的安装路径。 [[email protected] apr-1.5.0]# make && make install [[email protected] apr-1.5.0]# ls /usr/local/apr #编译安装后生成的程序文件 bin build-1 include lib [[email protected] apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr #编译apr-util,因为依赖于apr包,所以需要指定apr位置。 [[email protected] apr-util-1.5.3]# make -j 2 && make install [[email protected] apr-util-1.5.3]# ls /usr/local/apr-util bin include lib
(4)编译安装httpd-2.4
[[email protected] httpd-2.4.10]# ./configure --prefix=/usr/local/apache24 --enable-so --enable-ssl -enable-cgi --enable-rewrite --enable-modules=most --enable-mpms-shared=all --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-mpm=prefork #--enable 表示启用的特性 --with 表示依赖的包组,不指明路径会从默认路径查找 [[email protected] httpd-2.4.10]# make -j 4 && make install [[email protected] apache24]# ll total 56 drwxr-xr-x 2 root root 4096 Jan 13 20:40 bin #程序路径 drwxr-xr-x 2 root root 4096 Jan 13 20:40 build #编译安装时产生的相关文件 drwxr-xr-x 2 root root 4096 Jan 13 20:40 cgi-bin #cgi格式页面存放的位置 drwxr-xr-x 4 root root 4096 Jan 13 20:40 conf #配置文件 drwxr-xr-x 3 root root 4096 Jan 13 20:40 error #错误页面 drwxr-xr-x 2 root root 4096 Jan 13 20:33 htdocs #网页文件存放位置 drwxr-xr-x 3 root root 4096 Jan 13 20:40 icons #图标 drwxr-xr-x 2 root root 4096 Jan 13 20:40 include #头文件,二次开发所用 drwxr-xr-x 2 root root 4096 Jan 13 20:40 logs #日志 drwxr-xr-x 4 root root 4096 Jan 13 20:40 man #man手册 drwxr-xr-x 14 root root 12288 Jul 16 2014 manual #官方文档 drwxr-xr-x 2 root root 4096 Jan 13 20:40 modules #模块
(5)为httpd-2.4配置环境变量,以便系统启动之
[[email protected] ~]# export PATH=/usr/local/apache24/bin:$PATH #此种方法只对当前shell和子shell有效 [[email protected] ~]# echo $PATH /usr/local/apache24/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin [[email protected] ~]# vim /etc/profile.d/httpd2-4.sh #为httpd-2.4增加环境变量,对新登陆的用户有效。 export PATH=/usr/local/apache24/bin/:$PATH [[email protected] conf]# apachectl start #配置完环境变量之后就能使用自带的脚本启动httpd2.4 [[email protected] conf]# hash hits command 1 /usr/bin/vim 1 /usr/local/apache24/bin/httpd 2 /usr/local/apache24/bin/apachectl #由此可以看出是httpd2.4启动的而不是2.2 3 /bin/ls 3 /usr/sbin/ss
启动完成之后就能使用了
(6)但我们每次都使用自带的脚本启动该服务太过麻烦,我们可以复制一个http2.2的服务脚本到httpd2.4中。
[[email protected] init.d]# cp httpd httpd24 [[email protected] init.d]# vim httpd24 #复制服务脚本为2.4并编辑它 #if [ -f /etc/sysconfig/httpd ]; then #注释原来的配置文件 # . /etc/sysconfig/httpd #fi apachectl=/usr/local/apache24/bin/httpd #指apachectl程序为httpd2.4 httpd=${HTTPD-/usr/sbin/httpd} prog=httpd pidfile=${PIDFILE-/usr/local/apache24/logs/httpd.pid} #此处也制定为2.4的pid路径 lockfile=${LOCKFILE-/var/lock/subsys/httpd24} #更改为2.4 RETVAL=0 STOP_TIMEOUT=${STOP_TIMEOUT-10} [[email protected] init.d]# service httpd24 start #测试结果可以使用了 Starting httpd: [[email protected] init.d]# service httpd24 status httpd (pid 35131) is running... [[email protected] init.d]# service httpd24 stop Stopping httpd: [ OK ] [[email protected] init.d]# service httpd24 start Starting httpd: [ OK ]
CentOS 7:
yum install httpd
配置文件:
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.modules.d/*.conf
/etc/httpd/conf.d/*.conf
配置应用:
(1)切换使用的MPM
编辑配置文件/etc/httpd/conf.modules.d/00-mpm.conf
[[email protected] ~]# vim /etc/httpd/conf.modules.d/00-mpm.conf # Select the MPM module which should be used by uncommenting exactly # one of the following LoadModule lines: # prefork MPM: Implements a non-threaded, pre-forking web server # See: http://httpd.apache.org/docs/2.4/mod/prefork.html LoadModule mpm_prefork_module modules/mod_mpm_prefork.so # worker MPM: Multi-Processing Module implementing a hybrid # multi-threaded multi-process web server # See: http://httpd.apache.org/docs/2.4/mod/worker.html # #LoadModule mpm_worker_module modules/mod_mpm_worker.so #需要开启该MPM就把原来的注释掉 # event MPM: A variant of the worker MPM with the goal of consuming # threads only for connections with active processing # See: http://httpd.apache.org/docs/2.4/mod/event.html # #LoadModule mpm_event_module modules/mod_mpm_event.so
(2)基于IP的访问控制:(2.4中任何网页需要进行明确授权才能被访问)
[[email protected] conf]# vim httpd.conf <Directory "/var/www/html"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn‘t give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Require all granted #需要在此为根文档目录改为所有人访问 #Require all deny #不允许所有主机访问 #<RequireAll> #表示除了指定ip不能访问。 # Require all granted # Require not ip 172.16.100.2 #</RequireAll> </Directory>
控制特定的IP访问:
Require ip IPADDR:授权指定来源的IP访问;
Require not ip IPADDR:拒绝
控制特定的主机访问:
Require host HOSTNAME:授权指定来源的主机访问;
Require not host HOSTNAME:拒绝
HOSTNAME:
FQDN:特定主机
domin.tld:指定域名下的所
(3) 虚拟主机
基于FQDN的虚拟主机不再需要NameVirutalHost指令;