设为首页 收藏本站
查看: 1022|回复: 0

[经验分享] httpd2.4的新特性、以及基本应用

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-1-15 08:30:19 | 显示全部楼层 |阅读模式
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并关闭开机启动,防止覆盖此版本。         
1
2
3
[iyunv@Tzz ~]# service httpd stop
Stopping httpd:                                            [  OK  ]
[iyunv@Tzz ~]# chkconfig httpd off



(3)编译安装apr-1.5.0和apr-util-1.5.3  
1
2
3
4
5
6
7
8
9
[iyunv@Tzz apr-1.5.0]# ./configure --prefix=/usr/local/apr #apr-util依赖于apr所先编译安装apr,并指定一个不同与系统默认的安装路径。
[iyunv@Tzz apr-1.5.0]# make && make install
[iyunv@Tzz apr-1.5.0]# ls /usr/local/apr        #编译安装后生成的程序文件
bin  build-1  include  lib

[iyunv@Tzz apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr                         #编译apr-util,因为依赖于apr包,所以需要指定apr位置。
[iyunv@Tzz apr-util-1.5.3]# make -j 2 && make install
[iyunv@Tzz apr-util-1.5.3]# ls /usr/local/apr-util
bin  include  lib



(4)编译安装httpd-2.4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[iyunv@Tzz 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 表示依赖的包组,不指明路径会从默认路径查找

[iyunv@Tzz httpd-2.4.10]# make -j 4 && make install
[iyunv@Tzz 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配置环境变量,以便系统启动之
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[iyunv@Tzz ~]# export PATH=/usr/local/apache24/bin:$PATH   #此种方法只对当前shell和子shell有效
[iyunv@Tzz ~]# 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
[iyunv@Tzz ~]# vim /etc/profile.d/httpd2-4.sh    #为httpd-2.4增加环境变量,对新登陆的用户有效。

export PATH=/usr/local/apache24/bin/:$PATH   

[iyunv@Tzz conf]# apachectl start    #配置完环境变量之后就能使用自带的脚本启动httpd2.4
[iyunv@Tzz 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



启动完成之后就能使用了
wKiom1aXXPjxvwm2AAApSyIBsh8659.jpg

(6)但我们每次都使用自带的脚本启动该服务太过麻烦,我们可以复制一个http2.2的服务脚本到httpd2.4中。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[iyunv@Tzz init.d]# cp httpd httpd24
[iyunv@Tzz 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}




[iyunv@Tzz init.d]# service httpd24 start    #测试结果可以使用了
Starting httpd:
[iyunv@Tzz init.d]# service httpd24 status
httpd (pid  35131) is running...
[iyunv@Tzz init.d]# service httpd24 stop
Stopping httpd:                                            [  OK  ]
[iyunv@Tzz 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[iyunv@localhost ~]# 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中任何网页需要进行明确授权才能被访问)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[iyunv@localhost 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指令;


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-164565-1-1.html 上篇帖子: CentOS 6编译httpd-2.4.10 下篇帖子: apache负载均衡apache2.4.18+tomcat7(windows版)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表