apache服务器是目前因特网上最流行的web服务器之一,它的开源性,使得软件可以不断的更新和升级,这样安全性能也在不断的提高,下面我们就来体验一下red hat enterprise linux 下apache的搭建与配置。 1、apcahe服务安装的前期准备
red hat 下 apache服务httpd 默认情况下是没有被安装的,如果你在安装的时候没有定制软件的话。你可以通过以下命令来查询你的机子上是否已经安装了httpd服务。
# rpm -q httpd
如果给你返回没有安装此软件的信息,那也没事,安装httpd服务很简单。如果你有安装光碟或者镜像文件,你可以直接使用。在你挂载cdrom 或iso后,你可以去 /media/cdrom/Server/ 下寻找httpd相关的软件包。相关的软件包有:httpd、httpd-manual、httpd-tools等。当然你也直接去apache的官网上下载软件包。
另外有一点需要我们注意,安装httpd服务需要50MB的临时磁盘空间,安装后的apache服务需要占用10MB左右的磁盘空间
安装事例:
#rpm -ivh httpd-2.2.15-5.el6.i686.rpm
然后执行以下的命令启动httpd服务:
#service httpd start
最后我们在客户端浏览器中输入服务器的IP地址,如果可以进行访问,恭喜你安装成功了。
再补充两个命令:
#service httpd restart /*重启服务*/
#service httpd stop /*停止服务*/ 2、让apache服务器开机自启动:
图形化界面中单击“系统”—“管理”—“服务”,然后选择httpd服务,如果是红色的点将其点绿。
文字化界面中,我们可以 利用chkconfig命令来完成.
# chkconfig --level 2345 httpd on
如果是要关闭:
#chkconfig --level 2345 http off 3、apache服务的基本配置
apache的主配置文件是:/etc/httpd/conf/httpd.conf 。注意:httpd.conf的配置语句除了选项的参数值以外,所有选项命令均不区分大小写。
httpd.conf由3大部分构成:Global Environment(apache全局配置)、Main Server Configuration(主服务器配置)、Virtual Hosts(虚拟主机配置)。 首先介绍全局配置文件(### Section 1: Global Environment)
# (available at );
# you will save yourself a lot of trouble.
# Do NOT add a slash at the end of the directory path.
ServerRoot "/etc/httpd" //apache的根目录:/etc/httpd ,该目录下包括配置文件、记录文件、模块文件等。
# PidFile: The file in which the server should record its process
# identification number when it starts. Note the PIDFILE variable in
# /etc/sysconfig/httpd must be set appropriately if this location is
# changed.
PidFile run/httpd.pid // 在 /var/run/httpd.pid 保存着apache父进程的ID
# Timeout: The number of seconds before receives and sends time out.
Timeout 60 //超出时间控制,若客户端超过60s还没有连接上Server,或者Server超过60s还没有传送信息给客户端,则强制断线。
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
KeepAlive Off //表示不允许客户端同时提出多个请求,on即可允许。
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
MaxKeepAliveRequests 100 //表示每次联系允许的最大请求数目,数字越大,效率越高,0表示不受限制。
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
KeepAliveTimeout 15 //表示用户端的请求如果15s没有发出,则断线。
## Server-Pool Size Regulation (MPM specific)
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses (0.0.0.0)
#
#Listen 12.34.56.78:80
Listen 80 //设置监听端口
# Dynamic Shared Object (DSO) Support
/*****/ //加载dso模块,就像是windows中的dll(动态链接库)
# ExtendedStatus controls whether Apache will generate "full" status
# information (ExtendedStatus On) or just basic information (ExtendedStatus
# Off) when the "server-status" handler is called. The default is Off.
ExtendedStatus On //用于检测apache的状态信息。
# User/Group: The name (or #number) of the user/group to run httpd as.
# . On SCO (ODT 3) use "User nouser" and "Group nogroup".
# . On HPUX you may not be able to use shared memory as nobody, and the
# suggested workaround is to create a user www and use that user.
# NOTE that some kernels refuse to setgid(Group) or semctl(IPC_SET)
# when the value of (unsigned)Group is above 60000;
# don't use Group #-1 on these systems!
#
User apache
Group apache //设置apache工作时使用的用户和组。
然后介绍主服务器配置(### Section 2: 'Main' server configuration)
# ServerAdmin: Your address, where problems with the server should be
# e-mailed. This address appears on some server-generated pages, such
# as error documents. e.g. admin@your-domain.com
#
ServerAdmin root@localhost // 当服务器发生问题的时候,apache会自动向这个邮箱发送相关邮件。
#
# If your host doesn't have a registered DNS name, enter its IP address here.
# You will have to access it by its address anyway, and this will make
# redirections work in a sensible way.
#
#ServerName www.example.com:80 //设定apache服务器用于标识自身的名字和端口号。一般情况下,apache可以通过DNS服务器获得自身的名字,但服务器没有正式的
DNS名字时,需要我们设定。如果这个设置出错,将导致服务器不能正常启动。
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/var/www/html" //指定了主机中网页文件的根目录。