隐藏Apache的版本号及其它敏感信息
编辑配置文件httpd.conf
ServerSignature Off
ServerTokens Prod
参考配置操作
修改httpd.conf配置文件:
ServerSignature Off
ServerTokens Prod
存在ServerTokens值为Prod,ServerSignature值为Off
以专门的用户帐号和组运行Apache
根据需要为Apache创建用户、组
修改httpd.conf配置文件,添加如下语句:
User apache
Group apachegroup
其中apache、apachegroup分别是为Apache创建的用户和组。
User apache
Group apachegroup
Group,User
修改httpd.conf配置文件,添加如下语句:
User apache
Group apachegroup
其中apache、apachegroup分别是为Apache创建的用户和组。
1、根据不同用户,取不同的名称。
2、为用户设置适当的家目录和shell。
存在Group和user组
设备应配置日志功能,对运行错误、用户访问等进行记录,记录内容包括时间,用户使用的IP地址等内容
查看配置文件httpd.conf
编辑httpd.conf配置文件,设置日志记录文件、记录内容、记录格式。
LogLevel notice
ErrorLog logs/error_log
LogFormat “%h %l %u %t “%r” %>s %b “%{Accept}i” “%{Referer}i” “%{User-Agent}i”” combined
CustomLog logs/access_log combined
查看logs目录中相关日志文件内容,记录完整。
CustomLog,LogFormat,ErrorLog,LogLevel
编辑httpd.conf配置文件,设置日志记录文件、记录内容、记录格式。
LogLevel notice
ErrorLog logs/error_log
LogFormat “%h %l %u %t “%r” %>s %b “%{Accept}i” “%{Referer}i” “%{User-Agent}i”” combined
CustomLog logs/access_log combined
ErrorLog指令设置错误日志文件名和位置。错误日志是最重要的日志文件,Apache httpd将在这个文件中存放诊断信息和处理请求中出现的错误。若要将错误日志送到Syslog,则设置:ErrorLog syslog。
CustomLog指令设置访问日志的文件名和位置。访问日志中会记录服务器所处理的所有请求。
LogFormat设置日志格式。LogLevel用于调整记录在错误日志中的信息的详细程度,建议设置为notice。
用户日志CustomLog,日志格式LogFormat,错误日志ErrorLog,日志等级LogLevel这四个字段后面有配置的日志信息
禁止Apache列表显示文件
编辑httpd.conf配置文件,将Options Indexes FollowSymLinks中的Indexes 去掉,就可以禁止 Apache 显示该目录结构。Indexes 的作用就是当该目录下没有 index.html文件时,就显示目录结构
当WEB目录中没有默认首页如index.html文件时,不会列出目录内容
Indexes
编辑httpd.conf配置文件,
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
< /Directory >
将Options Indexes FollowSymLinks中的Indexes 去掉,就可以禁止 Apache 显示该目录结构。Indexes 的作用就是当该目录下没有 index.html文件时,就显示目录结构。
其中index.html即为默认页面,可根据情况改为其它文件。
存在Options Indexes FollowSymLinks
拒绝服务防范
编辑配置文件httpd.conf
Timeout 10 KeepAlive On
KeepAliveTimeout 15
AcceptFilter http data
AcceptFilter https data
AcceptFilter https data,AcceptFilter http data,KeepAliveTimeout 15,Timeout 10 KeepAlive On
编辑httpd.conf配置文件,
Timeout 10 KeepAlive On
KeepAliveTimeout 15
AcceptFilter http data
AcceptFilter https data
(2)重新启动Apache服务
同时存在AcceptFilter https data,AcceptFilter http data,KeepAliveTimeout 15,Timeout 10 KeepAlive On
删除缺省安装的无用文件
删除缺省安装的无用文件#rm %Apache_Home%/htdocs/* #rm %Apache_Home%/cgi-bin/#rm %Apache_Home%/manual#rm %Apache_Home%/httpd-2.2.4
删除缺省安装的无用文件#rm %Apache_Home%/htdocs/* #rm %Apache_Home%/cgi-bin/#rm %Apache_Home%/manual#rm %Apache_Home%/httpd-2.2.4
删除缺省HTML文件:
#rm -rf /usr/local/apache2/htdocs/*
删除缺省的CGI脚本:
#rm –rf /usr/local/apache2/cgi-bin/*
删除Apache说明文件:
#rm –rf /usr/local/apache2/manual
删除源代码文件:
#rm -rf /path/to/httpd-2.2.4*
根据安装步骤不同和版本不同,某些目录或文件可能不存在或位置不同。
htdocs,cgi-bin,manual的文件数都等于0
更改Apache服务器默认端口
修改httpd.conf配置文件,更改默认端口到8080
Listen x.x.x.x:8080
8080
(1)修改httpd.conf配置文件,更改默认端口到8080
Listen x.x.x.x:8080
(2)重启Apache服务
存在Listen x.x.x.x:8080
禁止Apache访问Web目录之外的任何文件
查看httpd.conf配置文件
编辑httpd.conf配置文件,
Order Deny,Allow
Deny from all
< /Directory>
编辑httpd.conf配置文件,
Order Deny,Allow
Deny from all
< /Directory>
Order Deny,Deny from all
编辑httpd.conf配置文件,
Order Deny,Allow
Deny from all
< /Directory>
设置可访问目录,
Order Allow,Deny
Allow from all
< /Directory>
其中/web为网站根目录。
根目录下面,存在Deny from all和Order Deny
Apache错误页面重定向
查看配置文件httpd.conf
ErrorDocument 400 /custom400.html
ErrorDocument 401 /custom401.html
ErrorDocument 403 /custom403.html
ErrorDocument 404 /custom404.html
ErrorDocument 405 /custom405.html
ErrorDocument 500 /custom500.html
Customxxx.html为要设置的错误页面。
ErrorDocument
(1) 修改httpd.conf配置文件:
ErrorDocument 400 /custom400.html
ErrorDocument 401 /custom401.html
ErrorDocument 403 /custom403.html
ErrorDocument 404 /custom404.html
ErrorDocument 405 /custom405.html
ErrorDocument 500 /custom500.html
Customxxx.html为要设置的错误页面。
(2)重新启动Apache服务
存在ErrorDocument
限制http请求的消息主体的大小
查看配置文件httpd.conf
LimitRequestBody 102400
LimitRequestBody 102400
编辑httpd.conf配置文件,修改为102400Byte
LimitRequestBody 102400
LimitRequestBody小于等于 102400