当前位置: 首页 > 图文教程 > 服务器 > Linux服务器 > 正确维护配置Apache服务器的方法 保护系统安全

Linux服务器
linux下用cron定时执行任务的方法
.htaccess绑定域名到子目录的方法
linux apache下虚拟主机配置方法
apache 局域网访问配置方案
linux Apache服务器系统安全设置与优化
linux中mac地址绑定方法
linux托盘不断闪烁之解决方法
Apache配置 虚拟转向实例
Apache No space left on device的解决办法
Apache rewrite的重写相关的参数说明
LINUX入门级常用命令20条整理
Ubuntu设置开机自动挂载所有格式硬盘分区
5个可能被你忽略的Linux安全设置方法
学习Apache的mod rewrite、access写法
改版时保留原链接,创建新的URL的方法
rsync中文手册之使用rsync实现网站镜像和备份linux
rsync 数据同步使用详解
linux URL的301重定向代码分析
eclipse3.2.2 + MyEclipse5.5 + Tomcat5.5.27 配置数据库连接池
Apache服务器二级域名的完美实现

Linux服务器 中的 正确维护配置Apache服务器的方法 保护系统安全


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-04   浏览: 48 ::
收藏到网摘: n/a

Apache是目前最流行的Web服务器端软件之一,它可以运行在几乎所有被广泛使用的计算机平台上。

Apache服务器快速、可靠、可通过简单的API扩展,其Perl/Python解释器可被编译到服务器中,并且完全免费,完全开放源代码。如果需要创建一个每天有数百万人访问的Web服务器,Apache可能是最佳的选择。
Apache是目前最流行的Web服务器端软件之一,它可以运行在几乎所有被广泛使用的计算机平台上。Apache服务器快速、可靠、可通过简单的API扩展,其Perl/Python解释器可被编译到服务器中,并且完全免费,完全开放源代码。如果需要创建一个每天有数百万人访问的Web服务器,Apache可能是最佳的选择。
  一、正确维护和配置Apache服务器
  虽然Apache服务器的开发者非常注重安全性,不过由于其项目非常庞大,难免会存在安全隐患。因此正确维护和配置Apache WEB服务器就显得很重要了。我们应注意的一些问题:
  1、Apache服务器配置文件
  Apache Web服务器主要有三个配置文件,位于/usr/local/apache/conf目录下,这三个文件是:
  httpd.conf----->主配置文件
  srm.conf------>填加资源文件
  access.conf--->设置文件的访问权限
  2、Apache服务器的目录安全认证
  在Apache Server中是允许使用.htaccess做目录安全保护的,欲读取保护目录需要先键入正确的用户帐号与密码,这可以做专门管理网页存放的目录或做为会员区等。在保护的目录放置一个档案,档案名为.htaccss。 % b?(5 ]
  AuthName “会员专区”
  AuthType “Basic”
  AuthUserFile “/var/tmp/xxx.pw”—>把password放在网站外,require valid-user到apache/bin目录,建立password档案% ./htpasswd -c /var/tmp/xxx.pw username1—>第一次建档要用参数“-c”% /htpasswd /var/tmp/xxx.pw username2,这样就可以保护目录内的内容,进入要用合法的用户。
  也可以采用在httpd.conf中加入: 
  options indexes followsymlinks 
allowoverride authconfig 
  order allow,deny 
  allow from all 
  3、Apache服务器访问控制
  我们就要看三个配置文件中的第三个文件了,即access.conf文件,它包含一些指令控制,允许什么用户访问Apache目录。应该把deny from all设为初始化指令,再使用allow from指令打开访问权限。
  order deny,allow
  deny from all
  allow from safechina.net
  设置允许来自某个域、IP地址或者IP段的访问。
  4、Apache服务器的密码保护问题
  我们再使用.htaccess文件把某个目录的访问权限赋予某个用户。系统管理员需要在httpd.conf或者rm.conf文件中,使用AccessFileName指令打开目录的访问控制。如:
  AuthName PrivateFiles
  AuthType Basic
  AuthUserFile /path/to/httpd/users
  require Phoenix
  # htpasswd -c /path/to/httpd/users Phoenix
  二、设置Apache服务器的WEB和文件服务器
  我们在Apache服务器上存放WEB服务器的文件,供用户访问,并设置/home/ftp/pub目录为文件存放区域,用http://download.ruanchen.com/pub/来访问。在防火墙上设置apache反向代理技术,由防火墙代理访问。 
1、Apache服务器的设置 
  Apache服务器采用默认配置。主目录为/home/httpd/html,主机域名为Phoenix.ruanchen.com, 且别名到www.ruanchen.com中,并设置srm.conf加一行别名定义,如下:
  Alias/pub/home/ftp/pub/ 
  更改默认应用程序类型定义如下: 
  DefaultType application/octet-stream 
  最后在/etc/httpd/conf/access.conf中增加一项定义:
  Options Indexes 
  AllowOverride AuthConfig 
  order allow,deny 
  allow from all 
  注意:Options Indexes允许在找不到index.html文件的情况下,允许列出目录/文件列表。AllowOverrideAuthConfig允许做基本的用户名和口令验证,这样的话,需要在/home/ftp/pub目录下放入.htaccess,内容如下:
  [root@ pub]#more.htaccess 
  AuthName Branch Office Public Software Download Area 
  AuthType Basic 
  AuthUserFile/etc/.usrpasswd 
  require valid-user 
  用# htpasswd -c /etc/.usrpasswd user1,分别创建不同的,允许访问/pub下文件服务的外部用户名和口令。
2、在防火墙上配置反向代理技术
  在/etc/httpd/conf/httpd.conf中加入NameVirtualHost xxx.xxx.xxx.xxx # xxx.xxx.xxx.xxx,这是防火墙外部在互联网上的永久IP地址: 
  servername www.ruanchen.com 
  errorlog /var/log/httpd/error_log 
  transferlog /var/log/httpd/access_log
  rewriteengine on 
  proxyrequests off 
  usecanonicalname off 
  rewriterule ^/(.*)$ http://xxx.xxx.xx.x/$1  Apache服务器的IP地址
  servername http://download.ruanchen.com/pub/
  errorlog /var/log/httpd/download/error_log 
  transferlog /var/log/httpd/download/access_log 
  rewriteengine on 
  proxyrequests off 
  usecanonicalname off 
  rewriterule ^/(.*)$ http://xxx.xxx.xx.x/$1  Apache服务器的IP地址
  设置防火墙上的DNS,让download.ruanchen.com和www.ruanchen.com都指向防火墙的外部网地址xxx.xxx.xxx.xxx。用http://www.ruanchen.com访问主页,用http://download.ruanchen.com/pub/访问公共文件的下载区。
  注意:还需要在apache服务器主机上建立目录/var/log/httpd/download/,否则会出错。另外,也可以设置防火墙主机上的/home/httpd/html/index.html的属性为750来阻止访问,这可以防止外部用户能访问到防火墙上Apache服务器的http://www.ruanchen.com。