其实我知识源码安装apache的时候遇到问题看懂啊这篇文章,本来想自己写一篇的,但是觉得这篇的内容更好,

原文连接Linux下安装Apr及其Apr-util的基本步骤

1.安装apr

# gzip -d apr-1.4.8.tar.gz

# tar xvf apr-1.4.8.tar

# 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 apr-util-1.5.2.tar.gz

# tar xvf apr-util-1.5.2.tar

# cd apr-util-1.5.2

# ./configure --prefix=/opt/apr-util --with-apr=/opt/apr

# make

# make install

 

3.安装pcre

# unzip -o pcre-8.33.zip

# 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 httpd-2.4.6.tar.gz

# tar xvf httpd-2.4.6.tar

# 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/rc.local(或者/etc/rc.d/rc.local)中加入如下一下

/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

解决方法:更新/etc/hosts文件,把里面的ip改成机器真实IP

 

启动时提示异常:httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

解决方法:编辑httpd.conf文件,搜索"#ServerName",添加ServerName localhost:80

 

日志文件里面有:AH01177: Failed to lookup provider 'shm' for 'slotmem': is mod_slotmem_shm loaded??

解决方法:编辑httpd.conf文件,把#LoadModule slotmem_shm_module modules/mod_slotmem_shm.so前的#号去掉

 

日志文件里面有:[alert] (EAI 3)Temporary failure in name resolution: mod_unique_id: unable to find IPv4 address of "gentoo"

Configuration Failed

解决方法:在 /etc/hosts 中加入gentoo 别名对应的本机ipok了,例如:

127.0.0.1       gentoo localhost localhost.localdomain localhost4 localhost4.localdomain4

::1             gentoo localhost localhost.localdomain localhost6 localhost6.localdomain6

 

日志文件里面有:[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应用

编辑httpd.conf文件(查找命令:find / -name httpd.conf),添加

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.查看httpddevel包是否已安装:rpm -qa | grep httpd-devel,或者find / -name apxs,如果没有对应的记录,表示此包未被安装,直接执行:

  yum -y install httpd-devel

 (不得不说,yum真是安装神器)

 

10.为了防止恶意用户对Apache进行攻击,我们需要安装mod_security这个安全模块,见文章:http://www.myhack58.com/Article/60/61/2012/32772.htm

怕文章失效,直接copy文本帖在这里:

mod_security 1.9.x模块的下载与安装

下载地址:http://www.modsecurity.org/download/index.html

建议使用1.9.x,因为2.x的配置指令与1.x完全不同,解压后进入解压目录,执行:

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

编译完成后,/home/apache/modules下会生成一个mod_security.so文件

然后kate /home/apache/conf/httpd.conf

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

#启用mod_security这个安全模块

LoadModule security_module modules/mod_security.so (这一句通常会被自动加入)

# 打开过滤引擎开关。如果是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:http://www.sina.com

SecFilter wget redirect:http://www.sina.com

#检测POST数据,注意,请甚用这个开关,可能会导致一些post页面无法访问。详细的信息,请察看www.modsecurity.org的文档,其中有详细的post编码要求。

#SecFilterScanPOST Off

# 缺省的动作

SecFilterDefaultAction deny,log,status:406

# 重新定向用户

#SecFilter xxx redirect:http://www.sina.com

# 防止操作系统关键词攻击

SecFilter /etc/*passwd

SecFilter /bin/*sh

# 防止double dot攻击

SecFilter “\.\./”

# 防止跨站脚本(CSS)攻击

SecFilter “<( |\n)*script”

# Prevent XSS atacks (HTML/Javascript injection)

SecFilter “<(.|\n)+>”

# 防止sql注入式攻击

SecFilter “delete[[:space:]]+from”

SecFilter “insert[[:space:]]+into”

SecFilter “select.+from”

#重定向exeasp请求

SecFilterSelective REQUEST_URI “\.exe” “redirect:http://www.google.com”

SecFilterSelective REQUEST_URI “\.asp” “redirect:http://www.google.com”

#下面是限制了upload.php文件只能用来上传jpeg.bmpgif的图片

#

#SecFilterInheritance On

#SecFilterSelective POST_PAYLOAD “!image/(jpeg|bmp|gif)”

#

#伪装服务器标识

SecServerSignature Microsoft-IIS/6.0

保存后重启apache即可!

 

 

为了防止Web服务器被DDoS攻击,我们需要安装mod_evasive这个防DDoS的模块(或见文档:Mod_evasive安装.mht

mod_evasive 1.10.xDDoS模块的下载与安装

下载地址:http://www.zdziarski.com/blog/wp-content/uploads/2010/02/mod_evasive_1.10.1.tar.gz

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

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

编译完成后,/home/apache/modules下会生成一个mod_evasive20.so文件

然后kate /home/apache/conf/httpd.conf

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

#启用mod_evasive for Apache 2.xDDoS模块

LoadModule evasive20_module modules/mod_evasive20.so (这一句通常会被自动加入)

#记录和存放黑名单的哈西表大小,如果服务器访问量很大,可以加大该值

DOSHashTableSize 3097

#同一个页面在同一时间内可以被统一个用户访问的次数,超过该数字就会被列为攻击,同一时间的数值可以在DosPageInterval参数中设置。

DOSPageCount 3

#同一个用户在同一个网站内可以同时打开的访问数,同一个时间的数值在DOSSiteInterval中设置。

DOSSiteCount 40

#设置DOSPageCount中时间长度标准,默认值为1

DOSPageInterval 2

#DOSSiteInterval 2 设置DOSSiteCount中时间长度标准,默认值为1

DOSSiteInterval 2

#被封时间间隔秒,这中间会收到 403 (Forbidden)的返回。

DOSBlockingPeriod 10

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

#DOSEmailNotify

#受到攻击时Apache运行用户执行的系统命令

#DOSSystemCommand “su - someuser -c ‘/sbin/… %s …’”

#攻击日志存放目录,BSD上默认是/tmp

#DOSLogDir “/var/lock/mod_evasive”

 

<IfModule mod_security.c>

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[ ]"

</IfModule>

Logo

更多推荐