码迷,mamicode.com
首页 > 其他好文 > 详细

Apache HTTP Server的源码安装配置及实现

时间:2014-08-11 10:22:02      阅读:334      评论:0      收藏:0      [点我收藏+]

标签:服务器   操作系统   基金会   linux   动态   

Apache HTTP Server简介

Linux下最有名的、功能最丰富的WEB服务器就属Apache HTTP Server(简称Apache)。

Apache HTTP Server是Apache软件基金会最有名的开源项目之一,它可以在大多数操作系统上运行。

目前官网的主要版本为2.2和2.4。CentOS 6使用2.2版本,CentOS 7使用2.4版本。

目前生产环境中部署2.2版本的居多,但是2.4版本有很多新的特性,下面就简要说明以下:

(1)运行时动态可装载MPM

在2.4版本中,MPM可以被编程成可装载的模块。在运行时,只要配置使用什么MPM即可。

(2)支持Event MPM

正式支持Event MPM,之前是作为试验性的。

(3)更好的异步读写支持

(4)在每模块及每目录分别使用不同的日志级别

(5)基于每一个请求可以使用<If>、<ElseIf>和<Else>配置

(6)增强版的表达式分析器

(7)可以毫秒级控制KeepAliveTimeout

(8)不再需要NameVirtualHost指令

(9)可以在配置中使用自定义变量

(10)比2.2版本使用更少的内存

(11)增加了很多新的Module,例如mod_proxy_fcgi, mode_ratelimit, mod_request, mod_remoteip。同时还增强了很多Module

(12)访问控制的改变

2.2 configuration:

Order deny,allow
Deny from all

2.4 configuration:

Require all denied

2.2 configuration:

Order allow,deny
Allow from all
2.4 configuration:

Require all granted

2.2 configuration:

Order Deny,Allow
Deny from all
Allow from example.org

2.4 configuration:

Require host example.org

鉴于V2.4引入了这么多新的功能,生产环境安装V2.4也是非常必要。

 

编译安装

准备工作

官网下载httpd-2.4.10.tar.bz2

实验环境是CentOS 6.5,默认已经安装了2.2版本,把V2.2停止掉。

[root@www named]# service httpd stop
[root@www named]# chkconfig httpd off
[root@www named]# chkconfig --list httpd
httpd              0:off    1:off    2:off    3:off    4:off    5:off    6:off
[root@www ~]# tar xf httpd-2.4.10.tar.bz2

apr安装

httpd依赖apr(Apache Portable Runtime),且2.4版本依赖较新的apr版本,要求是1.4以上。CentOS 6安装的是1.3.9

http://apr.apache.org下载apr-1.5.1.tar.bz2和apr-util-1.5.3.tar.bz2。

[root@www ~]# tar xf apr-1.5.1.tar.bz2
[root@www ~]# tar xf apr-util-1.5.3.tar.bz2

[root@www ~]# cd apr-1.5.1

[root@www apr-1.5.1]# ./configure --prefix=/usr/local/apr15

[root@www apr-1.5.1]# make && make install

[root@www ~]# cd ~/apr-util-1.5.3

[root@www apr-util-1.5.3]# ./configure --prefix=/usr/local/aprutil15 --with-apr=/usr/local/apr15/

[root@www apr-util-1.5.3]# make && make install

安装httpd

configure常用选项

名称 说明 取值
--prefix 程序安装目录,默认安装在/usr/local/apache2 /usr/local/apache24
--sysconfdir 配置文件目录 /etc/httpd24
--enable-so 启用DSO功能  
--enable-modules 空白字符分隔的module列表,也可以是"all" | "most" | "few" | "none" | "reallyall" most
--enable-ssl SSL/TLS支持(mod_ssl)  
--enable-cgi 支持CGI  
--enable-rewrite 服务器端重写  
--with-pcre 使用PCRE库  
--with-apr 指定apr路径 /usr/local/apr15/
--with-apr-util 指定apr-util路径 /usr/local/aprutil15/
--with-z 使用zlib库  
--enable-mpms-shared 空白字符分隔的MPM Module动态加载列表,可以是用all all
--with-mpm=MPM Apache使用的默认处理模型,MPM={event|worker|prefork|winnt} event

[root@www ~]# cd httpd-2.4.10
[root@www httpd-2.4.10]# ./configure --prefix=/usr/local/apache24 --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-z --with-pcre --with-apr=/usr/local/apr15/ --with-apr-util=/usr/local/aprutil15/ --enable-mpms-shared=all --with-mpm=event --enable-modules=most
[root@www httpd-2.4.10]# make && make install

 

安装目录和文件说明

/etc/httpd24 配置主目录
/etc/httpd24/extra 额外配置目录
/etc/httpd24/httpd.conf 主配置文件
/usr/local/apache24/htdocs 站点根目录
/usr/local/apache24/error 预置的错误文档目录
/usr/local/apache24/cgi-bin CGI目录
/usr/local/apache24/include 头文件目录,二次开发用,必要时可以导出
/usr/local/apache24/man 帮助手册,需要导出
/usr/local/apache24/modules DSO模块目录
/usr/local/apache24/bin 可执行文件目录
/usr/local/apache24/logs 日志目录

导出bin目录

[root@www ~]# cd /etc/profile.d/
[root@www profile.d]# vim httpd24.sh
PATH=/usr/local/apache24/bin:$PATH
export PATH

然后重启连接会话

导出man目录

在/etc/man.config 中加入一条

MANPATH /usr/local/apache24/man

即可生效

导出头文件目录

[root@www /]# ln -s /usr/local/apache24/include/ /usr/include/apache

apachectl

apachectl是/usr/local/apache24/bin下的一个shell脚本。通过它可以控制httpd的启动、关闭、重启、优雅重启动、优雅关闭。

所谓优雅,就是不蛮横,重启或者关闭前如果有连接就不会立即终止连接。

第一次尝试启动

[root@www ~]# apachectl start

[root@www ~]# ss -tnlp | grep :80
LISTEN     0      128                      :::80                      :::*      users:(("httpd",2308,4),("httpd",2309,4),("httpd",2310,4),("httpd",2311,4))

[root@www ~]# httpd -D DUMP_MODULES
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
headers_module (shared)
setenvif_module (shared)
version_module (shared)
mpm_event_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)

浏览器测试一下

bubuko.com,布布扣

 

实验

虚拟主机

server-status

基于用户的访问控制

HTTPS

未完待续……

Apache HTTP Server的源码安装配置及实现,布布扣,bubuko.com

Apache HTTP Server的源码安装配置及实现

标签:服务器   操作系统   基金会   linux   动态   

原文地址:http://me2xp.blog.51cto.com/6716920/1538324

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!