设为首页 收藏本站
查看: 764|回复: 0

[经验分享] 细述 Apache web server 的安装与配置 (1)

[复制链接]

尚未签到

发表于 2015-8-4 07:09:37 | 显示全部楼层 |阅读模式
一.、Apache web server 简介



Apache web server是一款开放源码的web服务器软件,由apache software foundation 开发和维护的。它是目前世界上使用最为广泛的web服务器软件,支持各种unix平台和windows平台。本文将介绍它在Red hat Linux 9中最基本的安装和配置。



二、软件的相关资源



官方网站:http://httpd.apache.org/

源码软件包:Apache 是开源的软件,可以去其官方网站http://httpd.apache.org/download.cgi下载。目前的最新稳定版本是httpd-2.0.53。

帮助文档:http://httpd.apache.org/docs-project/ 有该软件比较全面的帮助文档。

FAQ:http://httpd.apache.org/docs/misc/FAQ.html 回答了该软件的常见问题。

三.软件的安装



1.安装



由其官方网站中下载其源码软件包httpd-2.0.53.tar.gz。接下来我将对安装过程的一些重要步骤,给出其解释:




[iyunv@localhost root]#tar xzvf httpd-2.0.53.tar.gz
[iyunv@localhost root]#cd httpd-2.0.53
[iyunv@localhost httpd-2.0.53]#./configure
[iyunv@localhost httpd-2.0.53]#make
[iyunv@localhost httpd-2.0.53]#make install




tar xzvf httpd-2.0.53.tar.gz 解压缩软件包。



./configure 针对机器作安装的检查和设置,大部分的工作是由机器自动完成的,但是用户可以通过一些参数来完成一定的设置,其常用选项有:



./configure --help 察看参数设置帮助。



--prefix= 指定软件安装目录(默认/usr/local/apache2)。



--enable-modules= 指定需要加载的模块。



--enable-v4-mapped 支持ipv6的socket处理ipv4的连接。



可以设置的参数很多,可以通过 -help察看需要的,一般情况下,默认设置就可以了。



默认安装建立了/usr/local/apache2目录,下面介绍一下/usr/local/apache2的几个常用组成部分:



/usr/local/apache2/bin 其中主要是有服务器的程序。常用的有deamon程序httpd,和控制脚本apachectl。



/usr/local/apache2/conf 其中主要是服务器相关的配置文件。最主要的配置文件是httpd.conf。



/usr/local/apache2/htdocs 默认的网站html文件根目录。



/usr/local/apache2/cgi-bin 默认的cgi程序的存放目录。



2.启动:




[iyunv@localhost root]# /usr/local/apache2/bin/apachectl start
[iyunv@localhost root]# ps aux
[iyunv@localhost root]# netstat -an




如果不出什么问题,ps aux 应该可以查到httpd 的进程,或netstat -an 也可以看到80端口的服务已经起来了。如果要设置开机自启动web server,只需在/etc/rc.d/rc.local中加入一行



/usr/local/apache2/bin/apachectl start




#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
/usr/local/apache2/bin/apachectl start




四、软件的配置。



/usr/local/apache2/conf/httpd.conf 默认安装,所有的配置都有其默认值,接下来我介绍介绍一些常用的配置项:




















# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the
# directive.
#
# 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




设定apache 的侦听地址和端口。




#
# 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 you@example.com




设定apache 的管理员邮件地址。




#
# 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 "/usr/local/apache2/htdocs"




设定apache web server 的文档根目录,必须是绝对路径。





#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs-2.0/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all





设定文档根目录的权限控制,必须和DocumentRoot "/usr/local/apache2/htdocs" 中指定的目录一致。




#
# The index.html.var file (a type-map) is used to deliver content-
# negotiated documents.  The MultiViews Option can be used for the
# same purpose, but it is much slower.
#
DirectoryIndex index.html




指定该目录下的索引文档,




ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/"




映射cgi-bin的根目录,必须是绝对路径。





AllowOverride None
Options None
Order allow,deny
Allow from all





设定cgi-bin目录的读写权限,该目录项必须和上一条的设置一致。



五.安装使用的一些经验:



1.apache 进程的有效用户id默认为nobody。



出于安全方面的考虑,apache 服务器进程的默认有效 id 被设置为nobody,这就意味着该进程只拥有nobody的权限,所以必须确保nobody对设置的DocumentRoot 有足够权限。或者可以配置apache进程的有效id,但是推荐不要这样做。



2.如果网站的访问量不是很大可以考虑用xinetd超级进程来启动apache



(1)打开/usr/local/apache2/conf/httpd.conf,修改




ServerType inetd




(2)创建/etc/xinetd.d/apache,内容:




# default: on
# description: The Apache HTTP connections.
service http
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/sbin/httpd
port = 80
# log_on_success += DURATION USERID
# log_on_failure += USERID
# nice = 10
}




(3)重新启动xinetd:




#/etc/rc.d/init.d/xinetd restart




3.对IPV6的支持



随着计算机网络的不断发展和扩大,IPV6已经越来越为人们所接受,apache自2.0之后的版本开始支持IPV6,下面我就简单介绍一下apache针对ipv6的配置:



默认情况下,apache 使用映射到IPv4的IPv6地址,即安装配置时,默认./configure -enable-v4-map ,并且在配置文件http.conf中将是:




Listen 80




要使apache 区别对待IPV4与IPV6的连接,安装配置时,使用 ./configure -disable-v4-map , 对应配置文件中http.conf :




Listen [::]:80




这样 apache 就可以区别对待 IPV4 与IPV6的连接了。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-93812-1-1.html 上篇帖子: Apache + PHP 配置多站点 下篇帖子: 基于Apache(without ssl)的svn环境搭建
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表