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

[经验分享] 编译安装httpd-2.4.9及配置其相关的工作方式

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-9-9 08:28:30 | 显示全部楼层 |阅读模式
解决依赖关系

httpd-2.4.9依赖于较新版本的apr和apr-util,接下来就编译安装apr和apr-util

1、编译安装apr
1
2
3
4
# tar xf apr-1.5.0.tar.bz2
# cd apr-1.5.0
# ./configure --prefix=/usr/local/apr
# make && make install



2、编译安装apr-util
1
2
3
4
# tar xf apr-util-1.5.3.tar.bz2
# cd apr-util-1.5.3
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install




编译安装httpd-2.4.9

httpd-2.4.9编译过程中还需依赖于pcre-devel软件包,因此也需将其安装才行

提示:挂载光盘,切换到光盘下的Package目录执行
1
# rpm -ivh pcre-devel-7.8-6.el6.x86_64.rpm



1、编译安装httpd-2.4.9
1
2
3
4
5
6
7
# tar xf httpd-2.4.9.tar.bz2
# cd httpd-2.4.9
# ./configure --prefix=/usr/local/httpd24 --sysconfdir=/etc/httpd24 --enable-so
--enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre
--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
--enable-modules=most --enable-mpms-shared=all --with-mpm=event
# make && make install



2、编译/etc/httpd24/httpd.conf配置文件,添加如下行即可:

    PidFile "/var/run/httpd.conf"
    PidFile用于指定记录httpd进程号(PID)的文件位置

3、提供SysV服务脚本/etc/rc.d/init.d/httpd24
1
# vim /etc/rc.d/init.d/httpd24



脚本内容如下:
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server.  It is used to serve
# HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/httpd24/bin/apachectl
httpd=${HTTPD-/usr/local/httpd24/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
        echo -n $"Starting $prog: "
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}
stop() {
  echo -n $"Stopping $prog: "
  killproc -p ${pidfile} -d 10 $httpd
  RETVAL=$?
  echo
  [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
    echo -n $"Reloading $prog: "
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
        RETVAL=$?
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
    fi
    echo
}
# See how we were called.
case "$1" in
  start)
  start
  ;;
  stop)
  stop
  ;;
  status)
        status -p ${pidfile} $httpd
  RETVAL=$?
  ;;
  restart)
  stop
  start
  ;;
  condrestart)
  if [ -f ${pidfile} ] ; then
    stop
    start
  fi
  ;;
  reload)
        reload
  ;;
  graceful|help|configtest|fullstatus)
  $apachectl $@
  RETVAL=$?
  ;;
  *)
  echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
  exit 1
esac
exit $RETVAL



赋予脚本执行权限
1
# chmod +x /etc/rc.d/init.d/httpd24



将http24加入服务列表
1
2
# chkconfig --add httpd24
# chkconfig httpd24 on



4、启动http24服务并测试
1
# /etc/rc.d/init.d/httpd24 start



在浏览器中键入编译安装httpd-2.4.9的主机IP地址,如:10.170.2.1
wKiom1QNVOGiuY_bAACzUUtvtak267.jpg
此处需要说明的是,当你编译安装完httpd-2.4.9后,其DocumentRoot的默认路径为/usr/local/httpd24/htdocs,在此目录下,有一个index.html文件,更多详细内容请查看/etc/httpd24/httpd.conf配置文件

配置虚拟主机

在正式配置虚拟主机之前,需要进行说明的是:以前的httpd版本,配置虚拟主机、配置基于用户的访问控制以及配置httpd工作于https方式等只在主配置文件httpd.conf中,而编译安装的httpd-2.4.9将这些功能的配置分离出来形成了新的配置文件并利用Include包含的主配置文件中
1、编辑/etc/httpd24/httpd.conf配置文件,启动下面这项内容
1
Include /etc/httpd24/extra/httpd-vhosts.conf



2、编辑/etc/httpd24/extra/httpd-vhosts.conf文件

1
2
# cd /etc/httpd24/extra/
# vim httpd-vhosts.conf



将文件中的两个VirtualHost的所用内容注释掉,然后编辑如下内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

    DocumentRoot "/web/hosta"
    ServerName www.muluhe.org
   
        Require all granted
   



    DocumentRoot "/web/hostb"
    ServerName mail.muluhe.com
   
        Require all granted
   




3、编辑网页文件
1
2
3
4
5
6
# mkdir -pv /web/hosta
# mkdir -pv /web/hostb
# vim /web/hosta/index.html
    内容为:Hello,www.muluhe.org
# vim /web/hostb/index.html
    内容为:Hello,mail.muluhe.com



4、重启http24服务并测试
1
# /etc/rc.d/init.d/httpd24 restart



由于没有安装DNS服务器,因此利用本地文件对虚拟主机名进行解析
打开Windows主机上的C:WindowsSystem32driversetchosts文件,并添加对应IP地址与虚拟主机名,添加的内容为:
1
2
3
10.170.2.1 www.muluhe.com
10.170.2.1 mail.muluhe.com
10.170.2.1 www.muluhe.org



在浏览器中分别键入www.muluhe.comwww.muluhe.org、mai.muluhe.com,得到如下结果:
wKioL1QNUoKjH2P6AADB3dwNOhs534.jpg
wKiom1QNU7TA39K9AADamG8Hky4381.jpg
wKiom1QNU8LTtkDHAADdgACfJpU478.jpg

配置基于用户访问控制

1、编译配置文件/etc/httpd24/httpd.conf,启动下面的选项
1
Include /etc/httpd24/extra/httpd-userdir.conf



关闭下面的选项
1
Include /etc/httpd24/extra/httpd-vhosts.conf



2、编辑配置文件/etc/httpd24/extra/httpd-userdir.conf
1
2
# cd /etc/httpd24/extra/
# vim httpd-userdir.con



将文件中相对应的内容修改为:
1
2
3
4
5
6
7
8
9
UserDir "/usr/local/httpd24/htdocs/admin"

    AllowOverride AuthConfig
    Options none
    AuthType Basic
    AuthName "Admin Area."
    AuthUserFile /etc/httpd24/.htpasswd
    Require valid-user




3、提供相关文件

1
2
3
4
5
6
7
8
# cd /usr/local/httpd24/htdocs/
# mkdir admin
# vim index.html
    内容为:Hello,muluhe,Welcome to admin directory
# htpasswd -c -m /etc/httpd24/.htpasswd muluhe
New password:
Re-type new password:
Adding password for user muluhe



4、重启httpd24服务并测试
1
2
3
4
5
# /etc/init.d/httpd24 restart
Stopping httpd:                                            [  OK  ]
Starting httpd: AH00526: Syntax error on line 10 of /etc/httpd24/extra/httpd-userdir.conf:
Invalid command 'UserDir', perhaps misspelled or defined by a module not included in the server configuration
                                                           [FAILED]



呀哈,竟然出现错误,其大概的意思是说没有加载支持'UserDir'命令的模块,查看/etc/httpd24/extra/httpd-userdir.conf可以找到以下内容:
# Required module: mod_authz_core, mod_authz_host, mod_userdir
与配置文件/etc/httpd24/httpd.conf中的LoadModule中启动的模块作对比,发现没有启动LoadModule userdir_module modules/mod_userdir.so这个模块,将其启动起来再重启服务
1
2
3
# /etc/init.d/httpd24 restart
Stopping httpd:                                            [FAILED]
Starting httpd:                                            [  OK  ]



在浏览器中键入www.muluhe.com/admin,可以得到如下结果
wKiom1QNY4fR8FfaAAFjGtgnwUA995.jpg
输入用户名和密码可以得到如下结果
wKiom1QNY7Ly99oYAAGXfmRiEjQ716.jpg

配置httpd24工作于https

1、安装mod_ssl模块并查看
1
2
# yum -y install mod_ssl
# rpm -ql mod_ssl



2、为服务器端生成私钥,并为其提供证书
建立CA
1
2
3
4
5
# cd /etc/pki/CA
# (umask 077; openssl genrsa -out private/cakey.pem 2048)
# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650
# touch serial index.txt
# echo 01 > serial



生成证书请求
1
2
3
4
# mkdir /etc/httpd/ssl
# cd /etc/httpd/ssl
# (umask 077; openssl genrsa -out httpd.key 1024)
# openssl req -new -key httpd.key -out httpd.csr



签署证书
1
# openssl ca -in httpd.csr -out httpd.crt -days 1000



3、编辑配置文件/etc/httpd24/httpd.conf,启动下面的选项

1
2
3
Include /etc/httpd24/extra/httpd-ssl.conf
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule ssl_module modules/mod_ssl.so



4、编辑配置文件/etc/httpd24/extra/httpd-ssl.conf,修改下面的选项

1
2
3
4
DocumentRoot "/usr/local/httpd24/htdocs/ssl"
ServerName www.muluhe.com
SSLCertificateFile "/etc/httpd24/ssl/httpd.crt"
SSLCertificateKeyFile "/etc/httpd24/ssl/httpd.key"



5、安装证书
复制/etc/pki/CA/cacert.pem文件到Windows桌面并重命名为cacert.crt,其具体的安装步骤为:
双击桌面上"cacert.crt"-->点击安装"安装证书(I)..."-->点击"下一步"-->选择"将所有的证书放入下列存储(P)"-->点击"浏览(R)..."-->点击"下一步"-->点击"完成"-->在新的窗口中点击"yes"-->在新的窗口点击"确定"
6、编辑网页文件
1
2
3
4
# mkdir /usr/local/httpd24/htdocs/ssl
# cd /usr/local/httpd24/htdocs/ssl
# vim index.html
    其内容为:Hello,SSL,I'm here!



7、重启httpd24服务并测试
1
# /etc/rc.d/init.d/httpd24 restart



在浏览器中键入www.muluhe.com,可以得到如下结果
wKiom1QNvoiTz6GuAADB3dwNOhs734.jpg
在浏览器中键入https://www.muluhe.com,可以得到如下结果
wKioL1QNvszwgwTOAADlfGmf6Oc160.jpg




运维网声明 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-24567-1-1.html 上篇帖子: 配置apache以fastcgi运行php 下篇帖子: apache配置多个虚拟主机
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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