Apache-2.4.9增加了一些新特新,编译安装Apache之前先要准备好安装环境即各种开发包组的安装这里我们就不一一介绍,

   Apache-2.4会依赖更高版本的apr、apr-util,apr是一个底层库可以让apache跨平台的工具,我们这里使用apr-1.5.0.tar.bz2、apr-1.5.0.tar.bz2

  如果你的系统上事先安装了httpd较低的版本需要先停止服务,并且让下次开机不能自动开启:

#service httpd stop

#chkconfig httpd off

  如果要使Apache能使用正则表达式则还需要安装一个pcre-devel,环境准备好,我们就开始实施编一:译安装httpd的操作:

  1:安装pcre-devel

#yum -y install pcre-devel

  2:安装apr

#tar -xf apr-1.5.0.tar.bz2

#cd apr-1.5.0

#cat README

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d

#./configure --prefix=/usr/local/apr

#make && make install

3:安装apr-util

#tar -xf apr-util

# ./configure --prefix=/usr/local/apr-util1.5.3 --with-apr=/usr/local/apr1.5/

因为apr-util是apr的工具所以在安装apr-util的时候需要让它知道apr在哪里:使用--with-apr=/usr/local/arp1.5

#make && make install

4:安装httpd-2.4.9

#tar -xf httpd-2.4.9.tar.bz2 -C /usr/local/

#cd /usr/local/httpd-2.4.9

创建连接:

#ln -sv httpd-2.4.9 apache

编译安装:

#./configure --prefix=/usr/local/httppd249 --sysconfdir=/etc/httpd249 --enable-so --enable-rewrite --enable-cgi --enable-ssl --enable-modules=most --enable-mpms-share=all --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-mpm=event --with-zlib --with-pcre

#make && make install

安装完成以后

1:导出头文件

# ln -sv /usr/local/apache/include/ /usr/include/httpd249

注意:编译安装的httpd没有库文件,所以这里不需要导出库文件。如果有也需要导出库文件


2:导出帮助手册man

#vim /etc/man.config

导入以后需要注意:用#man httpd 不一定看到的是新版本的帮助信息,可以用:

#man -M /usr/local/heeptd.2.4.9/man httpd。这样看到的是新的版本的帮助信息。


3:把二进制文件写入到环境变量PATH中:

# vim /etc/profile.d/apache.sh


4:制作新版httpd的服务脚本

#cd /etc/rc.d/init.d

#cp httpd apache

#vim apache

修改

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_02

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_03

需要在配置文件/etc/httpd.249/httpd.conf中写入pid文件的

# vim /etc/httpd249/httpd.conf

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_04

把服务加入到开机服务里面:

#chkconfig --add apache

下次开机启动:

#chkconfig apache on

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_05

启动服务:

#service apache start

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_06

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_07



二:虚拟主机的实现:

   与2.2内核不同,2.4的虚拟主机有了一个单独的配置文件:

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_08

  大家注意这两个文件:一个是配置虚拟主机的,一个是配置https的,一会我们实现https的时候就会用到httpd-ssl.conf 这个配置文件。

  1:关闭中心主机,开启vhost的配置文件功能

# vim /etc/httpd249/httpd.conf

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_09

  这两要注释掉包括<Directory></Directory>内的所有配置。

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_10

  这个要启用。

  2:编辑vhost的配置文件

# vim /etc/httpd249/extra/httpd-vhosts.conf

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_11

  当然这些目录你得事先创建好,并在里面配置好各自的index.html

  大家要注意到是:虚拟主机必须配置<Directory></Directory>属性,否则你访问会被拒绝。错误403,没权限。

  3:验证结果:配置完我们就可以验证了。当然做测试你需要把你windows主机的Host文件改改。

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_12

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_13



三:https的实现:


    Α:需要创建CA,并自签

      生成私钥

#(umask 077; openssl genrsa -out /etc/pki/tls/CA/prevate/cakey.pem 2048)

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_14     生成自签证书:

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_15

  给我们的web服务器申请个证书,我的实验都是在同一台机子上做到所以一会签证的时候就直接签了

  生成web的私钥:

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_16

   生成证书签署请求

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_17

  给web签署证书:

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_18

 这时候会报错,打开openssl.cnf 会发现我们有3个文件没创建

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_19

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_20   创建这三个文件:

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_21    serial文件是记录申请的证书的编号的我们让它从01开始。

   再颁发证书:

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_22

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_23

   证书申请完了,开始整我们的配置文件:

 1:启用主配置文件里ssl配置文件的功能:

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_24

2:再启用两个模块,否则会报错

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_25

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_26

  我们来展示下不启用这俩模块的报错信息:大家谨记

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_27    回归正题,配置我们的ssl的配置文件:

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_28

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_29

    验证我们的成果:

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_30


导出证书到windows主机上添加到信任的证书

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_31

   在看效果:

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_32

四:我们可以顺便把基于用户的访问控制演示了:

   修改Directory属性

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_33

 使用htpasswd创建一个文件and验证用户

#man htpasswd

htpasswd -b[cmdpsD] passwordfile username password

# htpasswd -c -m ./.htpasswd hadoop

New password:

Re-type new password:

Adding password for user hadoop

 验证:

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_34httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_35


五:网页状态页面的现实:

  1:主配置文件设置:启用2项

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_36httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_37

  # vim /etc/httpd249/extra/httpd-info.conf  

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_38

 当然这里也可以做基于用户的访问控制,看效果:

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_39


六:CGI的配置使用:

    主配置文件:启用两个模块,如同示:

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_40

   直接写个可以执行脚本,给个执行权限

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_41

  在主配置文件里有已经定义好的脚本路径别名

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_42

 我们只需要把这个脚本mv到这个目录下即可,看看测试结果:

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_43

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_44

    CGI是开放动态网站用到的一种协议。是基于SUID、SGID运行目录下的脚本文件的。比较危险。所以在生产环境中已不使用。


七:基于mod_deflate实现压缩传输

   基于主配置文件做设置即可

   启用模块

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_45

  在配置文件里编辑如下内容:

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_46

  打开网页测试:

httpd-2.4.9.tar.bz2的编译安装配置以及CGI、虚拟主机、https、mod_deflate、mod_status的实现。_CGI、虚拟主机、https、mod_d_47

   


   OK,所有功能均以实现。不足之处请指教。