-
Linux
下安装
Apr
及其
Apr-util
的基本步骤
1.
安装
apr
# gzip -d
# tar xvf
# cd apr-1.4.8
# ./configure
--prefix=/opt/apr
(注意:如果执行时出现此错误
configure: error: no acceptable C
compiler found in $$PATH
执行:
yum -y install gcc
前提条件:该机器可访问互联网。
然后再执行:
./configure
--prefix=/opt/apr
)
# make
# make install
2.
安装
apr-util
# gzip -d
# tar xvf
# cd apr-util-1.5.2
#
./configure --prefix=/opt/apr-util --with-
apr=/opt/apr
# make
# make
install
3.
安装
pcre
# unzip -o
# cd pcre-8.33
# ./configure --prefix=/opt/pcre
(注意:如果执行时出现此错误
configure: error: You need a C++
compiler for C++ support
执行:
yum install -y gcc
gcc-c++
前提条件:该机器可访问互联网。
然后再执行:
./configure
--prefix=/opt/pcre
)
# make
# make install
4.
安装
apache
# gzip -d
# tar xvf
# cd httpd-2.4.6
#
./configure --prefix=/opt/apache --enable-
modules=all --enable-mods-shared=all --enable-
proxy
--enable-proxy-connect
--enable-proxy-ftp
--enable-
proxy-http
--enable-proxy-ajp
--enable-proxy-balancer
--enable-rewrite
--enable-
status
--with-apr=/opt/apr
--with-apr-util=/opt/apr-util/ --with-
pcre=/opt/pcre
# make
# make
install
5.
配置
apache
开机自启动
在
/etc/
(或者
/etc/r
c.d/
)中加入如下一下
/opt/apache/bin/apachectl -k start
查看是否正常启动:
ps -ef | grep httpd
[root@LINUX128 ~]# ps -ef|grep httpd
root
2645
1
0 20:43 ?
00:00:00
/opt/apache/bin/httpd -k start
daemon
2646
2645
0 20:43 ?
00:00:00
/opt/apache/bin/httpd -k start
daemon
2647
2645
0 20:43 ?
00:00:00
/opt/apache/bin/httpd -k start
daemon
2648
2645
0 20:43 ?
00:00:00
/opt/apache/bin/httpd -k start
root
2749
2472
5 20:46
pts/0
00:00:00 grep httpd
6.
常见问题解决:
启动时提示异常:
AH00558:
httpd:
Could
not
reliably
determine
the
server's
fully
qualified
domain
name,
using
192.168.2.128.
Set
the
'ServerName'
directive
globally
to
suppress
this
message
解决方法:更新
/e
tc/hosts
文件,把里面的
ip
改成机器真实
IP
;
启动时提示异常:
httpd:
Could not reliably determine the server's fully
qualified domain name,
using 127.0.0.1
for ServerName
解决方法:编辑
文件,搜索
,添加
Serv
erName localhost:80
日志文件里面有:
AH01177: Failed to
lookup provider 'shm' for 'slotmem': is
mod_slotmem_shm
loaded??
解
p>
决
方
法
:
编
辑
文
件
,
把
#LoadModul
e
slotmem_shm_module
modules
/mod_slotmem_
前的
#
号
去掉
日志文件里面有:
[alert] (EAI
3)Temporary failure in name resolution:
mod_unique_id: unable to
find IPv4
address of
Configuration Failed
解决方法:在
/etc/hosts
中加入
gentoo
别名对应的本机
ip
就
ok
了,例如:
127.0.0.1
gentoo
localhost
omain
localhost4
omain4
::1
gentoo
localhost
omain
localhost6
omain6
日志文件里面有:
[error]
(111)Connection
refused:
proxy:
HTTP:
attempt
to
connect
to
127.0.0.1:8080 (localhost) failed
[error]
ap_proxy_connect_backend disabling worker for
(localhost)
解决方法:运行:
/usr/sbin/setsebool
httpd_can_network_connect true
7.
如果操作系统已经自带了
httpd
(查找命令:
find /
-name httpd
)
,
那上述过
程就可以免了。
8.
反向代理
Tomcat
应用
编辑
文件(查找命令:
find / -name
)
,添加
ProxyPass /
http://192.168.137.220:8060/
ProxyPassReverse /
http://192.168.137.220:8060/
*
注意:发布的应用的访问路径一定要是根目录,否则就要像这样:
ProxyPass /app1
http://192.168.137.220:8060/app1
ProxyPassReverse /app1
http://192.168.137.220:8060/app1
9.
查看
httpd
的<
/p>
devel
包是否已安装:
rpm
-qa | grep httpd-
devel
,或者
find / -name apxs
,如
果没有对应的记录,表示此包未被安装,直接执行:
yum -y
install httpd-devel
(不得不说,<
/p>
yum
真是安装神器)
10.
为了防止恶意用户对
Apache
进行攻击,
我们需要安装
mod_security
这个安全模块,
见文
章:
/Article/60/61/2012/
怕文章失效,直接
copy
文本帖在这里:
mod_security
1.9.x
模块的下载与安装
下载地址:
/download/
建
议使用
1.9.x
,因为
2.x
的配置指令与
1.x
完全不同,解压后进入解
压目录,执行:
/home/apache/bin/apxs -cia
mod_security.c
编译完成后,
/home/a
pache/modules
下会生成一个
mod_
文件
然后
kate
/home/apache/conf/
加入以下选项(如果没有的话)
#<
/p>
启用
mod_security
这个安全
模块
LoadModule
security_module modules/mod_
(
这一句通常会被自动加入
)
# <
/p>
打开过滤引擎开关。如果是
Off
,那么
下面这些都不起作用了。
SecFilterEngine
On
#
把设置传递给字目录
SecFilterInheritance Off
# <
/p>
检查
url
编码
SecFilterCheckURLEncoding On
#
检测内容长度以避免堆溢出攻击
#SecFilterForceByteRange 32 126
#
日志的文件和位置。一定要先建立好目录,否则
apache
重新启动的时候会报错。
SecAuditLog logs/audit_log
#
debug
的设置
#SecFilterDebugLog
logs/modsec_debug_log
#SecFilterDebugLevel 1
#
当匹配
chmod,wget
等命令的时候
p>
,
重新定向到一个特殊的页面
,
让攻击者知难而退
SecFilter
chmod redirect:
SecFilter wget
redirect: