RHCE实验文档— APACHE配置实验一: 实现安全的APACHE( https )实验环境: Redhat 6.0平台软件包: httpd-2.2.15-5.el6.x86_64.rpm mod_ssl.x86_64 1:2.2.15-5.el6.rpm实验要求: 搭建一个基本的web服务,并且能够实现通过https协议访问.步骤一: 安装软件包[root@station ~]# yum -y install httpd mod_ssl步骤二: 查看配置文件中证书路径是否启用.[root@station ~]# vim /etc/httpd/conf.d/ssl.conf# certificate can be generated using the genkey(1) command.SSLCertificateFile /etc/pki/tls/certs/localhost.crt –公钥# Server Private Key:# If the key is not combined with the certificate, use this# directive to point at the key file. Keep in mind that if# you've both a RSA and a DSA private key you can configure# both in parallel (to also allow the use of DSA ciphers, etc.)SSLCertificateKeyFile /etc/pki/tls/private/localhost.key –私钥注:红色字体分别指出了公钥和私钥的路径,在企业六中默认自动创建了这两个证书.可以直接使用这两个自签证书.步骤三:创建用于测试的主页面:[root@station ~]# echo "this is test for https" >/var/www/html/index.html 步骤四:启动服务并将服务设置为开机自启动[root@station ~]# service httpd startStarting httpd: [ OK ][root@station ~]# chkconfig httpd on步骤五:测试总结:实验到第五步就已经实现了一个最基本的https的web服务器,在实际生产环境中,证书部分可以通过搭建CA证书服务器来签发,或者向第三方的权威CA服务器来申请,从而提高证书的可信性.如果使用第三方的证书时,大家需要注意调整证书的路径.实验二:创建基于不同域名的虚拟主机实验环境: Redhat 6.0平台软件包: httpd-2.2.15-5.el6.x86_64.rpm实验要求: 下载服务器文件ftp: ///pub/x86_64/rhce/station.html到指定目录/var/www/html,实现通过域名能够访问。
建一个web虚拟主机,下载服务器文件ftp: ///pub/x86_64/rhce/www.html,到指定目录/virtual ,要求通过域名能够访问步骤一: 安装软件包[root@station ~]# yum -y install httpd步骤二:创建实验所要的目录并调整其selinux环境[root@station ~]# mkdir /virtual[root@station ~]# chcon --reference /var/www/html/ /virtual/[root@station ~]# ll -Zd /virtual/drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /virtual/步骤三:下载所需的测试页面并更改其主面名.[root@station html]# cd /virtual/[root@station virtual]# wget ftp:///pub/x86_64/rhce/www.html[root@station virtual]#mv www.html index.html[root@station virtual]# cd /var/www/html/[root@station html]# wget ftp:///pub/x86_64/rhce/station.html[root@station html]#mv station.html index.html步骤四:检查各虚拟主机主页的selinux环境[root@station html]# ll -Z index.html-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html[root@station html]# ll -Z /virtual/index.html-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 /virtual/index.html步骤五:修改主配置文件.NameVirtualHost 172.24.20.15<VirtualHost 172.24.20.15>DocumentRoot /var/www/htmlServerName </VirtualHost><VirtualHost 172.24.20.15>DocumentRoot /virtualServerName </VirtualHost>步骤六:重启httpd服务,并测试.[root@station html]# service httpd restartStopping httpd: [ OK ]Starting httpd: [ OK ][root@station html]# curl this is station site for RHCE6.0[root@station html]# curl this is www site for RHCE6.0总结:此实验中大家重点需要注意的是selinux环境的问题.另如果兄弟们实验环境中没有DNS服务器配合,可以通过临时修改hosts文件来实现域名的解析.实验三:实验环境: Redhat 6.0平台软件包: httpd*实验要求:搭建基本的CGI环境,能够实现通过浏览器访问时执行服务器端的脚本.步骤一:安装软件包[root@station html]# yum -y install httpd*步骤二:创建CGI程序的根目录[root@station ~]# mkdir /cgi-bin步骤三:调整新建目录的selinux环境[root@station ~]#chcon --reference /var/www/cgi-bin/ /cgi-bin/步骤四:修改配置文件:[root@station cgi-bin]# vim /etc/httpd/conf/httpd.conf#ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"–将此行注释ScriptAlias /cgi-bin/ "/cgi-bin/" -–添加此行步骤五:创建测试脚本[root@station ~]#cd /cgi-bin/[root@station cgi-bin]#vim first.pl#!/usr/bin/perlprint "Content-type: text/html\n\n";print "Hello, World.";[root@station cgi-bin]#chmod 777 first.pl步骤六:重启服务[root@station html]# service httpd restartStopping httpd: [ OK ]Starting httpd: [ OK ]步骤七:测试访问总结:此实验中用户如果需要自己创建CGI根目录,请将原来目录的别名行注释了.另外就是selinux环境搞定就可以了实验四:实现APACHE基本用户认证实验环境: Redhat 6.0平台软件包: httpd*实验要求:当用户访问web站点时,要求用户验证.当用户输入用户名:bob 密码:redhat时能够通过验证并正常访问服务器主页.(bob用户非系统本地帐户)步骤一:安装软件包[root@station html]# yum -y install httpd*步骤二:修改主配置文件[root@station cgi-bin]# vim /etc/httpd/conf/httpd.confNameVirtualHost 172.24.20.15<VirtualHost 172.24.20.15>DocumentRoot /var/www/htmlServerName <Directory /var/www/html>AuthName "hongda"AuthType "Basic"AuthUserFile "/var/www/html/.htpasswd"Require user bob</Directory></VirtualHost><VirtualHost 172.24.20.15>DocumentRoot /virtualServerName </VirtualHost>步骤三:创建用户认证文件:[root@station cgi-bin]# htpasswd -cm /var/www/html/.htpasswd bobNew password: redhatRe-type new password: redhatAdding password for user bob步骤四:重启服务并验证[root@station html]# service httpd restartStopping httpd: [ OK ] Starting httpd: [ OK ]扩展部分:此实验中我们使用了bob用户为非系统帐户,如果生产环境要求我们使用本地系统帐户进行验证,我们只需要把上面的第三步使用以下方法实现就可以了,其余步骤同上:[root@station ~]# cut -d: -f1-2 /etc/shadow >/var/www/html/.htpasswd实验五:实现APACHE的ldap认证实验环境: Redhat 6.0平台实验环境中需要有ldap服务器软件包: httpd* sssd实验要求:当用户访问web站点时,要求用户验证.当用户输入ldap服务器提供的帐户后能过通过验证并能够正常访问主页面。