2024年3月20日发(作者:)

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-balancer

--enable-proxy-ftp

--enable-rewrite

--enable-proxy-http

--enable-status

--enable-proxy-ajp

--with-apr=/opt/apr

--with-apr-util=/opt/apr-util/ --with-pcre=/opt/pcre

# make

# make install

5.

配置

apache

开机自启动

/etc/

(或者

/etc/rc.d/

)中加入如下一下

/opt/apache/bin/apachectl -k start

看是否正常启动:

ps -ef | grep httpd [root@LINUX128 ~]# ps -ef|grep httpd

root

daemon

daemon

daemon

root

2645

2646

2647

1 0 20:43 ?

2645

2645

0 20:43 ?

0 20:43 ?

00:00:00 /opt/apache/bin/httpd -k

start

00:00:00 -k

/opt/apache/bin/httpd start

00:00:00 -k

start

-k

start

/opt/apache/bin/httpd

00:00:00

2648 2645 0 20:43 ?

/opt/apache/bin/httpd

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

解决方法:更新

/etc/hosts

文件,把里面的

ip

改成机器真实

IP

httpd: Could not reliably determine the server's fully qualified domain

name,

using 127.0.0.1 for ServerName

启动时提示异

解决方法:编辑

文件,搜索

"#ServerName"

,添加

ServerName localhost:80

日志文件里面

有:

loaded??

解决方

法:

AH01177: Failed to lookup provider 'shm' for 'slotmem': is mod_slotmem_shm

编 辑

文 件 , 把

#LoadModule slotmem_shm_module

modules/mod_slotmem_

前的

#

号去掉

日志文件里面有:

[alert] (EAI 3)Temporary failure in name resolution: mod_unique_id: unable to

omain6

find IPv4 address of "gentoo"

Configuration Failed

解决方法:在

/etc/hosts

中加入

127.0.0.1

omain4

::1

gentoo

别名对应的本机

gentoo localhost

ip

ok

了,例如:

omain

localhost4

gentoo localhost

omain

localhost6

日志文件里面有:

[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

8.

反向代理

Tomcat

应用

编辑

文件(查找命令:

find / -name

),添加

ProxyPass / 192.168.137.220:8060/

ProxyPassReverse / 192.168.137.220:8060/

#

注意:发布的应用的访问路径一定要是根目录,否则就要像这样:

ProxyPass /app1 192.168.137.220:8060/app1

ProxyPassReverse /app1 192.168.137.220:8060/app1

9.

查看

httpd

devel

包是否已安装:

rpm -qa | grep httpd-devel

,或者

find / -name apxs

,如

果没有对应的记录,表示此包未被安装,直接执行:

yum -y install httpd-devel

(不得不说,

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/apache/modules

下会生成一个

mod_

文件 然后

kate

/home/apache/conf/

加入以下选项(如果没有的话)

#

启用

mod_security

这个安全模块

LoadModule security_module modules/mod_ (

这一句通常会被自动加入

#

打开过滤引擎开关。如果是

Off

,那么下面这些都不起作用了。

SecFilterEngine On

#

把设置传递给字目录

SecFilterInheritance Off

#

检查

url

编码

SecFilterCheckURLEncoding On

#

检测内容长度以避免堆溢出攻击

#SecFilterForceByteRange 32 126

#

日志的文件和位置。一定要先建立好目录,否则

apache

重新启动的时候会报错。

SecAuditLog logs/audit_log

# debug

的设置

#SecFilterDebugLog logs/modsec_debug_log

#SecFilterDebugLevel 1

#

当匹配

chmod,wget

等命令的时候

,

重新定向到一个特殊的页面

,

让攻击者知难而退

SecFilter chmod redirect:

SecFilter wget redirect:

#

检测

POST

数据,注意,请甚用这个开关,可能会导致一些

#SecFilterScanPOST Off

#

缺省的动作

SecFilterDefaultAction

deny,log,status:406

"

#

重新定向用户

#SecFilter xxx redirect:

#

防止操作系统关键词攻击

SecFilter /etc/*passwd

SecFilter /bin/*sh

#

防止

double dot

攻击

SecFilter .

/

#

防止跨站脚本

(CSS

攻击

SecFilter

SecFilter

SecFilter

SecFilter

post

页面无法访问。详细的信

息,请察看

的文档,其中有详细的

post

编码要求。

n<)*(s|cript

n<)+(.>|

delete**:space:+++from

insert**:space:+++into

# Prevent XSS atacks (HTML/Javascript injection)

#

防止

sql

注入式攻击

SecFilter

select.+from

#

重定向

exe

asp

请求

SecFilterSelective REQUEST_URI

SecFilterSelective REQUEST_URI

#

#SecFilterInheritance On

#SecFilterSelective POST_PAYLOAD

#

#

伪装服务器标识

.exe

”“ “

redirect:

.asp

”“ “

redirect:

#

下面是限制了

文件只能用来上传

gif

的图片

!image/(jpeg|bmp|gif)

SecServerSignature

Microsoft-IIS/6.0 "

保存后重启

apache

即可!

为了防止

Web

服务器被

DDoS

攻击,我们需要安装

mod_evasive

这个防

DDoS

的模块(或见 文档:

Mod_evasive

安装

.mht

)

mod_evasive 1.10.x

DDoS

模块的下载与安装 下载地址:

/blog/wp-

content/uploads/2010/02/mod_evasive_

解压后进入解压目录,执行

/home/apache/bin/apxs -cia mod_evasive20.c

编译完成后,

/home/apache/modules

下会生成一个

mod_

文件 然后

kate

/home/apache/conf/

加入以下选项(如果没有的话)

#

启用

mod_evasive for Apache 2.x

DDoS

模块

LoadModule evasive20_module modules/mod_ (

这一句通常会被自动加入

) #

记录和存放黑

名单的哈西表大小,如果服务器访问量很大,可以加大该值

DOSHashTableSize 3097 #

同一个页面在同一时间内可以被统一个用户访问的次数,超过该数字就会被列

为攻击,同 一时间的数值可以在

DosPageInterval

参数中设置。

DOSPageCount 3

#

同一个用户在同一个网站内可以同时打开的访问数,同一个时间的数值在

DOSSiteInterval

中设置。

DOSSiteCount 40

#

设置

DOSPageCount

中时间长度标准,默认值为

DOSPageInterval 2

#DOSSiteInterval 2

设置

DOSSiteCount

中时间长度标准,默认值为

DOSSiteInterval 2

#

被封时间间隔秒,这中间会收到

403 (Forbidden)

的返回。

DOSBlockingPeriod 10 #

设置受到攻击时接收攻击信息提示的邮箱地址。

#DOSEmailNotify

#

受到攻击时

Apache

运行用户执行的系统命令

#DOSSystemCommand

susomeuser -c

/sbin/

%s •••'”

#

攻击日志存放目录,

BSD

上默认是

/tmp

#DOSLogDir

/var/lock/mod_evasive

SecFilterEngine On

SecFilterCheckURLEncoding On

SecFilterDefaultAction "deny,log,status:500"

#SecFilterForceByteRange 32 126

#SecFilterScanPOST On

SecAuditLog logs/audit_log

###

SecFilter "../"

#####

SecFilter /etc/*passwd

SecFilter /bin/*sh

#for css attack

SecFilter "<( | )*script"

SecFilter "<(.| )+>"

#for sql attack

SecFilter "delete[ ]+from"

SecFilter "insert[ ]+into"

SecFilter "select.+from"

SecFilter "union[ ]+from"

SecFilter "drop[ ]"

1

1