lyd2004888 发表于 2016-12-31 11:59:38

apache安全配置tips

  原文:http://www.javaarch.net/jiagoushi/1105.htm
  apache安全配置tips
  1.apache出错页面隐藏apache版本和操作系统信息
  默认情况下apache的404页面会出现apache的版本和OS信息,这个会成为一个主要的安全威胁点。那么如何隐藏这些信息,打开apache的httpd.conf配置文件,里面ServerSignature这个参数默认为on,然后再通过ServerTokens Prod这个选项在每个response中只返回apache字符串,而不返回具体的版本信息
  # vim /etc/httpd/conf/httpd.conf
  ServerSignature Off
  ServerTokens Prod
  2.禁用目录列表
  默认情况下apache会列出index file的目录内容,这个会暴露一些动态脚本比如php的源码,可以通过httpd.conf增加下面选项禁用列出目录内容
  <Directory /var/www/html>
  Options -Indexes
  </Directory>
  3.经常更新到最新版的apache,解决一些apache的漏洞
  # httpd -v 查看apache版本,
  根据不同的linux版本更新apache
  # yum update httpd
  # apt-get update apache2
  4.禁用不需要的模块,找到httpd.conf的loadModule行,对于不需要的用#注释掉
  # grep LoadModule /etc/httpd/conf/httpd.conf
  # have to place corresponding `LoadModule' lines at this location so the
  # LoadModule foo_module modules/mod_foo.so
  LoadModule auth_basic_module modules/mod_auth_basic.so
  LoadModule auth_digest_module modules/mod_auth_digest.so
  LoadModule authn_file_module modules/mod_authn_file.so
  LoadModule authn_alias_module modules/mod_authn_alias.so
  LoadModule authn_anon_module modules/mod_authn_anon.so
  5.用单独的账号和组账号运行apache
  apache默认用nobody和daemon账号,为了安全问题我们需要用一个受限制的账号来运行apache,我们可以先增加另外的账号
  # groupadd http-web
  # useradd -d /var/www/ -g http-web -s /bin/nologin http-web
  然后在httpd.conf修改user和group
  User http-web
  Group http-web
  6.使用allow和deny来限制对目录的访问,对于根目录
  <Directory />
  Options None
  Order deny,allow
  Deny from all
  </Directory>
  7.禁用apache的符号链接,apache默认是开启符号链接的,下面关闭
  Options -FollowSymLinks
  打开:
  # Enable symbolic links
  Options +FollowSymLinks
  8.禁用server side include和CGI
  Options -Includes
  Options -ExecCGI
  对某个特定目录禁用
  <Directory "/var/www/html/web1">
  Options -Includes -ExecCGI
  </Directory>
  9.限制request请求包的大小,如果太大,可能会造成DOS攻击,在文件上传服务中需要限制上传文件的大小,通过参数LimitRequestBody设置
  下面设置request大小为512k
  <Directory "/var/www/myweb1/user_uploads">
  LimitRequestBody 512000
  </Directory>
  10.保护DDOS攻击,比如TimeOut :设置request的超时时间,默认300s,MaxClients :设置最大连接客户端默认512,,KeepAliveTimeout :设置长连接的超时时间,默认5s,LimitRequestFields:设置请求header字段大小,默认100
  11.开启apache日志,设置ErrorLog 和CustomLog 
  <VirtualHost *:80>
  DocumentRoot /var/www/html/example.com/
  ServerName www.example.com
  DirectoryIndex index.htm index.html index.php
  ServerAlias example.com
  ErrorDocument 404 /story.php
  ErrorLog /var/log/httpd/example.com_error_log
  CustomLog /var/log/httpd/example.com_access_log combined
  </VirtualHost>
  12.安装设置SSL
  # openssl genrsa -des3 -out example.com.key 1024
  # openssl req -new -key example.com.key -out exmaple.csr
  # openssl x509 -req -days 365 -in example.com.com.csr -signkey example.com.com.key -out example.com.com.crt
  <VirtualHost 172.16.25.125:443>
  SSLEngine on
  SSLCertificateFile /etc/pki/tls/certs/example.com.crt
  SSLCertificateKeyFile /etc/pki/tls/certs/example.com.key
  SSLCertificateChainFile /etc/pki/tls/certs/sf_bundle.crt
  ServerAdmin ravi.saive@example.com
  ServerName example.com
  DocumentRoot /var/www/html/example/
  ErrorLog /var/log/httpd/example.com-error_log
  CustomLog /var/log/httpd/example.com-access_log common
  </VirtualHost>
页: [1]
查看完整版本: apache安全配置tips