当前位置: 首页 > 图文教程 > 服务器 > Linux服务器 > 用实验快速掌握web服务器Apache

Linux服务器
Linux/UNIX命令dd简介
分级防御 针对Linux服务器攻击防范
Linux下Apache配置虚拟主机+SSL
Linux系统的服务器攻防技术详解
Linux环境使用TC进行服务器流量控制方法
Apache服务器使用.htaccess实现图片防盗链
整理一些linux系统一些常用的系统信息查看命令
修改Linux系统下22端口两种方法
加强Linux系统在安全方面的管理
linux创建一定大小文件命令--dd
linux下configure命令详细介绍
使用linux cd命令来改变所在目录
巧用linux cd命令和Pushd切换目录
linux中Find命令的使用
DB2在Linux和UNIX环境下的安装
教程:三万元搭建LINUX服务器集群
Linux集群的虚拟化技术面临的挑战
Linux 服务器的安全隐患以及防范对策
使用linux下的TC进行服务器流量控制
在linux上使用BIND建立DNS服务器

Linux服务器 中的 用实验快速掌握web服务器Apache


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


Apache是大多数linux版本的标准web服务器,掌握他的意义就非常大。

本文以实验的方式,让读者快速掌握Apache的基本配置。

[实验目的]

1.Apache的基本安装和配置。

2.Apache中应用CGI。

3.基本代理配置。

[实验要求]

1.两台互通的RH8.0机。

2.这两台机已配置过DNS。

[实验步骤]

1.准备工作。

由于web服务器与DNS关系非常紧密。作好这步准备工作。

“用实验快速掌握DNS配置”。这篇文章发表在linuxsir的网络版块。

DNS能够实现的主要功能就是能能解析:station1.exmaple1.com,server1.example1.com两个域名的IP,如果你想在/etc/hosts中实现,我想也不是不可以。这里不提倡这么做。

本文中作法比较教条,这里指明机器1为:server1.example1.com,机器2为:

station1.example1.com.读者也可以自己变通。

2.在机器1上安装和配置简单的Apache。

1)检查下列包是否安装,

httpd
httpd-manual

缺什么,装什么。

2)开启httpd服务

#servicehttpdstart

如果开启失败,查看/var/log/httpd/下的相关日志,切记要在/etc/hosts中添加类似

192.168.0.254example1.comserver1的一行。

3)检查/etc/httpd/conf/httpd.conf中,有下列一行活动

DocumentRoot/var/www/html

4)用一个浏览器打开:

http://server1.example1.com

如果是正常情况,你会看到Apache的介绍页面。

5)创建新的目录和html文件。

#mkdir-p/var/www/virtual/server1.example1.com/html
#vi/var/www/virtual/server1.example1.com/html/index.html
Server1.example1.com

6)编辑/etc/httpd/conf/httpd.conf,末尾追加下列文本。

NameVirtualHost192.168.0.254

ServerNameserver1.example1.com
[email protected]
DocumentRoot/var/www/virtual/server1.example1.com/html
ErrorLoglogs/server1.example1.com-error_log
CustomLoglogs/server1.example1.com-access_logcombined

OptionsIndexesIncludes

7)确保DNS能够解析你的VirtualHost

#hostserver1.example1.com

8)重新启动httpd

#servicehttpdrestart

如果启动失败,看/var/log/httpd/下的相应日志,会告诉你具体哪里错误。

9)在浏览器里能够看到你自己写的网页了吗?

http://server1.example1.com

10)在机器2上能看到http://server1.example1.com吗?

3.机器1,在Apache中应用CGI

1)编辑/etc/httpd/conf/httpd.conf,在块中添加下列一行:

ScriptAlias/cgi-bin//var/www/virtual/server1.example1.com/cgi-bin/

2)创建目录,创建文件。

#mkdir/var/www/virtual/server1.example1.com/cgi-bin
#vi/var/www/virtual/server1.example1.com/cgi-bin/test.sh

#!/bin/bash
echoContent-Type:text/html
echo

echo“”
echoMyusernameis:
whoami
echo
echoMyidi??獡s????ゐ?!s:
id
echo
echoHereis/etc/passwd:
cat/etc/passwd
echo“”

3)改变test.sh的执行权限:

#chmod555test.sh

4)重启httpd服务:

#servicehttpdrestart

若有错,看日志。

5)浏览:http://server1.example1.com/cgi-bin/test.sh

6)机器2能浏览http://server1.example1.com/cgi-bin/test.sh吗?

4.基本代理配置:

1)机器1,检查squid包装了没有,没有的话,则进行安装。

2)机器1,启动squid服务。

#servicesquidstart

有问题?看/var/log/messages.

3)机器1,浏览器中设置代理端口为3128,举例:在mozilla:Edit|Preferences...|

Advanced|proxies中,设定手动,端口为:3128,其他不动。

机器2,浏览器中类似设置为:手动,http代理:192.168.0.254端口:3128。

4)此时,机器1,能浏览server1.exmaple1.com.,若平时能上internet,此时也正常上internet。

5)机器2,不能浏览server1.example1.com或internet。

查看/var/log/httpd/*的日志文件,原因是什么?

6)编辑/etc/squid/squid.conf,在aclCONNECTmethodCONNECT行下,添加下列一行:

aclexamample1src192.168.0.0/24

找到INSERTYOUROWNRULE(S)HERE增加下列一行:

http_accessallowexample1

7)重启squid

#servicesquidrestart

有错?看日志。

8)此时,机器2能够浏览server1.example1.com或internet网页.

9)编辑/etc/squid/squid.conf,在aclexamample1src192.168.0.0/24行下添加

aclotherdenydstdomain.sina.com.cn

在http_accessallowexample1下添加:

http_accessdenyotherdeny

10)重启squid.

#servicesquidrestart

有错?看日志。

11)机器2,仍能浏览http://www.sina.com.cn,为什么

12)编辑/etc/squid/squid.conf,把http_accessdenyotherdeny放到

http_accessallowexample1前面,重启squid,机器2还能看到

http://www.sina.com.cn吗

[实验总结]

Apache配置是否成功,与DNS有很大关系,所以,要求读者先花时间作好DNS工作。本文

以最通俗的方式,教你简单的配置Apache,如果想深入掌握它,还得研究Apache2.0的文档。