189 8069 5689

Apache-2.2.32安装配置

Apache-2.2.32安装配置

创新互联长期为上1000+客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为福安企业提供专业的成都网站设计、成都网站建设,福安网站改版等技术服务。拥有十年丰富建站经验和众多成功案例,为您定制开发。

 

一、Apache服务安装

 

1.创建目录,下载Apache源码包

[root@apache ~]# mkdir/home/wangning/tools -p

[root@apache ~]# cd/home/wangning/tools

[root@apache tools]# wgethttp://mirror.bit.edu.cn/apache/httpd/httpd-2.2.32.tar.gz

 

2.解压,安装Apache

[root@apache tools]# tar zxvfhttpd-2.2.32.tar.gz

[root@apache tools]# cdhttpd-2.2.32

[root@apache httpd-2.2.32]# yum-y install zlib zlib-devel   ###安装zlib依赖包

[root@apache httpd-2.2.32]#./configure --prefix=/application/apache2.2.32 --enable-deflate --enable-expires--enable-headers --enable-modules=most --enable-so --with-mpm=worker--enable-rewrite

[root@apache httpd-2.2.32]#make

[root@apache httpd-2.2.32]#make install

[root@apache httpd-2.2.32]# ln-s  /application/apache2.2.32//application/apache

 

3.检查语法,启动Apache服务,两种启动方法

[root@apache httpd-2.2.32]#/application/apache/bin/apachectl -t

[root@apache httpd-2.2.32]#/application/apache/bin/apachectl start ###启动Apache服务

httpd: apr_sockaddr_info_get()failed for apache(报错1)

httpd: Could not reliablydetermine the server's fully qualified domain name, using 127.0.0.1 forServerName(报错2)

[root@apache httpd-2.2.32]#/application/apache/bin/httpd -k start ###启动Apache服务

在hosts文件里添加×××部分,报错1消除

[root@apache ~]# cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4localhost4.localdomain4

::1         localhost localhost.localdomainlocalhost6 localhost6.localdomain6

10.0.0.20   apache

在配置文件里添加×××部分,报错2消除

[root@apache ~]# grepServerName /application/apache/conf/httpd.conf           

# ServerName gives the name andport that the server uses to identify itself.

#ServerName www.example.com:80

ServerName 127.0.0.1:80

 

4.检查Apache服务是否正常启动

[root@apache httpd-2.2.32]#lsof -i:80

[root@apache httpd-2.2.32]# ps-ef|grep httpd

[root@apache httpd-2.2.32]#curl  127.0.0.1      ###测试浏览器是否可以访问

Itworks!

 

二、Apache服务器的首页,结构目录和虚拟主机配置

 

1.默认首页所在的目录,默认首页为index.html

[root@apache htdocs]# pwd

/application/apache/htdocs

2.修改默认首页为wangning.html,×××为增加的内容

[root@apache conf]# grepDirectoryIndex /application/apache/conf/httpd.conf

# DirectoryIndex: sets the filethat Apache will serve if a directory

DirectoryIndex wangning.html index.html

[root@apache htdocs]# touch/application/apache/htdocs/wangning.html

[root@apache htdocs]# echo"www.wangning.com" >/application/apache/htdocs/wangning.html

[root@apache htdocs]# ls/application/apache/htdocs

index.html  wangning.html

[root@apache htdocs]#/application/apache/bin/apachectl -t

[root@apache htdocs]# /application/apache/bin/apachectl  graceful

[root@apache htdocs]# curl10.0.0.20      ###测试修改首页成功

www.wangning.com

 

3.当默认首页不存在的时候,Apache服务默认会在浏览器页面显示目录结构

[root@apache htdocs]# cd/application/apache/htdocs/

[root@apache htdocs]# mv index.htmlindex.html.bak

在浏览器中输入Apache服务器地址,默认是显示目录结构的

Apache-2.2.32安装配置

在配置文件中Indexes前面加上一个减号,或者将  Indexex删掉,就不显示目录结构了

[root@apache htdocs]# grep -B 13"Options Indexes FollowSymLinks" /application/apache/conf/httpd.conf

    #

    # Possible values for the Options directiveare "None", "All",

    # or any combination of:

    #  Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

    #

    # Note that "MultiViews" must benamed *explicitly* --- "Options All"

    # doesn't give it to you.

    #

    # The Options directive is both complicatedand important.  Please see

    #http://httpd.apache.org/docs/2.2/mod/core.html#options

    # for more information.

    #

    Options -Indexes FollowSymLinks

[root@apache htdocs]# /application/apache/bin/apachectl  -t

[root@apache htdocs]#/application/apache/bin/apachectl gracefulApache-2.2.32安装配置

这样就不显示目录结构了

 

4.配置Apache服务器的虚拟主机(基于域名、端口号、ip)

1)        基本信息如下

域名

站点目录

www.wangning.com

/var/html/www

bbs.wangning.com

/var/html/bbs

blog.wangning.com

/var/html/blog

 

2)创建站点目录

[root@apache /]# mkdir/var/html/{www,bbs,blog}  -p

[root@apache /]# for n in wwwbbs blog;do echo "http://$n.wangning.com">/var/html/$n/index.html;done      ###在这三个目录里分别创建一个index.html文件,并写入三个网址

[root@apache /]# for n in wwwbbs blog;do cat /var/html/$n/index.html;done

http://www.wangning.com

http://bbs.wangning.com

http://blog.wangning.com

3)在虚拟主机配置文件末尾增加以下内容,并把文件里两个默认的虚拟主机样例删掉

[root@apache /]# cat/application/apache/conf/extra/httpd-vhosts.conf

    ServerAdmin 1198143315@qq.com

    DocumentRoot "/var/html/www"

    ServerName www.wangning.com

    ServerAlias wangning.com

    ErrorLog "logs/www-error_log"

    CustomLog "logs/www-access_log"common

 

    ServerAdmin 1198143315@qq.com

    DocumentRoot "/var/html/bbs"

    ServerName bbs.wangning.com

    ErrorLog "logs/bbs-error_log"

    CustomLog "logs/bbs-access_log"common

 

    ServerAdmin 1198143315@qq.com

    DocumentRoot "/var/html/blog"

    ServerName blog.wangning.com

    ErrorLog "logs/blog-error_log"

    CustomLog "logs/blog-access_log"common

4)配置Apache的主配置文件httpd.conf,将×××部分内容前的注释符井号去掉

[root@apache /]# egrep -C 1 "Virtualhosts|httpd-mpm.conf" /application/apache/conf/httpd.conf 

# Server-pool management (MPMspecific)

Include conf/extra/httpd-mpm.conf

 

--

 

# Virtual hosts

Include conf/extra/httpd-vhosts.conf

在Apache主配置文件httpd.conf末尾添加如下内容

    Options -Indexes FollowSymLinks

    AllowOverride None

    Order allow,deny

    Allow from all

[root@apache /]#/application/apache/bin/apachectl  -t

[root@apache /]#/application/apache/bin/apachectl graceful

 

5)配置Linux和windows本地hosts文件

linux的hosts文件

[root@apache /]# cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4localhost4.localdomain4

::1         localhost localhost.localdomainlocalhost6 localhost6.localdomain6

10.0.0.20   apache

10.0.0.20  www.wangning.com bbs.wangning.com blog.wangning.com

Windows的C:\Windows\System32\drivers\etc\hosts文件

# localhost name resolution ishandled within DNS itself.

#       127.0.0.1      localhost

#       ::1            localhost

10.0.0.20 www.wangning.com bbs.wangning.comblog.wangning.com

 

6)最后在windows的浏览器里分别访问三个域名,大功告成了^*^

Apache-2.2.32安装配置Apache-2.2.32安装配置Apache-2.2.32安装配置

 

三、Apache服务器的日志格式配置

1.日志格式分为两种:

通用日志格式(CommonLog  Format)

组合日志格式(CombinedLog  Format)

默认是通用格式,一般工作中习惯用组合日志

2.设置三台虚拟主机的日志格式为组合模式

将httpd-vhosts.conf中common都改为combined即可

[root@apache ~]# cat /application/apache/conf/extra/httpd-vhosts.conf

    ServerAdmin 1198143315@qq.com

    DocumentRoot "/var/html/www"

    ServerName www.wangning.com

    ServerAlias wangning.com

    ErrorLog "logs/www-error_log"

    CustomLog "logs/www-access_log" combined

 

    ServerAdmin 1198143315@qq.com

    DocumentRoot "/var/html/bbs"

    ServerName bbs.wangning.com

    ErrorLog "logs/bbs-error_log"

    CustomLog "logs/bbs-access_log" combined

 

    ServerAdmin 1198143315@qq.com

    DocumentRoot "/var/html/blog"

    ServerName blog.wangning.com

    ErrorLog "logs/blog-error_log"

    CustomLog "logs/blog-access_log" combined

 

四、Apache服务器的日志轮询配置

1.Apache日志轮询工具有两种,一种是Apache自带的轮询工具rotatelog,另一种是第三方日志轮询工具cronolog。一般工作中采用第三方工具cronolog,Apache自带的rotatelog工具之前有过丢日志的情况,所以就一直延续用第三方cronolog日志工具

2.下载并编译安装日志轮询cronolog工具

[root@apache tools]# wgethttp://down1.chinaunix.net/distfiles/cronolog-1.6.2.tar.gz

[root@apache tools]# tar zxvfcronolog-1.6.2.tar.g

[root@apache tools]# cdcronolog-1.6.2

[root@apache cronolog-1.6.2]#./configure

[root@apache cronolog-1.6.2]#make

[root@apache cronolog-1.6.2]#make install

安装完后会生成一个cronolog命令

[root@apache cronolog-1.6.2]#ls /usr/local/sbin/cronolog

/usr/local/sbin/cronolog

 

3.配置httpd-vhosts.conf文件,以blog.wangning.com虚拟主机为例配置,让access_log日志轮询(注意日志路径要写绝对路径)

[root@apache /]# cat/application/apache/conf/extra/httpd-vhosts.conf

    ServerAdmin 1198143315@qq.com

    DocumentRoot "/var/html/blog"

    ServerName blog.wangning.com

    ErrorLog "logs/blog-error_log"

    CustomLog "|/usr/local/sbin/cronologapp/logs/blog-access_%Y%m%d.log" combined

[root@apache /]# ls /app/logs/           ###显示配置成功

blog-access_20170528.log  blog-access_20170627.log

 

五、Apache服务器的版本号隐藏配置

1.将full改为Prod,on改为off

[root@apache ~]# egrep"ServerTokens|ServerSignature"  /application/apache/conf/extra/httpd-default.conf

# ServerTokens

ServerTokens Prod

ServerSignature off

 

2.将×××那行前的注释符井号去掉

[root@apache ~]# grep "Includeconf/extra/httpd-default.conf" /application/apache2.2.32/conf/httpd.conf

Include conf/extra/httpd-default.conf

 

3.检查语法,重新加载Apache服务,测试已无版本号了

[root@apache ~]#/application/apache/bin/apachectl -t

[root@apache ~]#/application/apache/bin/apachectl graceful

[root@apache ~]# curl -Iwww.wangning.com           

HTTP/1.1 200 OK

Date: Tue, 27 Jun 2017 14:24:45GMT

Server: Apache

Last-Modified: Sat, 27 May 201715:52:29 GMT

ETag:"82fa4-18-5508370f3e458"

Accept-Ranges: bytes

Content-Length: 24

Content-Type: text/html

 


网页题目:Apache-2.2.32安装配置
分享路径:http://cdxtjz.cn/article/jsdcps.html

其他资讯