溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Apache-2.2.32安裝配置

發(fā)布時(shí)間:2020-06-30 07:24:36 來源:網(wǎng)絡(luò) 閱讀:496 作者:茁壯的小草 欄目:建站服務(wù)器

Apache-2.2.32安裝配置

 

一、Apache服務(wù)安裝

 

1.創(chuàng)建目錄,下載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.檢查語(yǔ)法,啟動(dòng)Apache服務(wù),兩種啟動(dòng)方法

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

[root@apache httpd-2.2.32]#/application/apache/bin/apachectl start ###啟動(dòng)Apache服務(wù)

httpd: apr_sockaddr_info_get()failed for apache(報(bào)錯(cuò)1

httpd: Could not reliablydetermine the server's fully qualified domain name, using 127.0.0.1 forServerName(報(bào)錯(cuò)2

[root@apache httpd-2.2.32]#/application/apache/bin/httpd -k start ###啟動(dòng)Apache服務(wù)

hosts文件里添加×××部分,報(bào)錯(cuò)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

在配置文件里添加×××部分,報(bào)錯(cuò)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服務(wù)是否正常啟動(dòng)

[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      ###測(cè)試瀏覽器是否可以訪問

<html><body><h2>Itworks!</h2></body></html>

 

二、Apache服務(wù)器的首頁(yè),結(jié)構(gòu)目錄和虛擬主機(jī)配置

 

1.默認(rèn)首頁(yè)所在的目錄,默認(rèn)首頁(yè)為index.html

[root@apache htdocs]# pwd

/application/apache/htdocs

2.修改默認(rèn)首頁(yè)為wangning.html,×××為增加的內(nèi)容

[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      ###測(cè)試修改首頁(yè)成功

www.wangning.com

 

3.當(dāng)默認(rèn)首頁(yè)不存在的時(shí)候,Apache服務(wù)默認(rèn)會(huì)在瀏覽器頁(yè)面顯示目錄結(jié)構(gòu)

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

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

在瀏覽器中輸入Apache服務(wù)器地址,默認(rèn)是顯示目錄結(jié)構(gòu)的

Apache-2.2.32安裝配置

在配置文件中Indexes前面加上一個(gè)減號(hào),或者將  Indexex刪掉,就不顯示目錄結(jié)構(gòu)了

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

<Directory"/application/apache2.2.32/htdocs">

    #

    # 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安裝配置

這樣就不顯示目錄結(jié)構(gòu)了

 

4.配置Apache服務(wù)器的虛擬主機(jī)(基于域名、端口號(hào)、ip

1)        基本信息如下

域名

站點(diǎn)目錄

www.wangning.com

/var/html/www

bbs.wangning.com

/var/html/bbs

blog.wangning.com

/var/html/blog

 

2)創(chuàng)建站點(diǎn)目錄

[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      ###在這三個(gè)目錄里分別創(chuàng)建一個(gè)index.html文件,并寫入三個(gè)網(wǎng)址

[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)在虛擬主機(jī)配置文件末尾增加以下內(nèi)容,并把文件里兩個(gè)默認(rèn)的虛擬主機(jī)樣例刪掉

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

<VirtualHost *:80>

    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

</VirtualHost>

 

<VirtualHost *:80>

    ServerAdmin 1198143315@qq.com

    DocumentRoot "/var/html/bbs"

    ServerName bbs.wangning.com

    ErrorLog "logs/bbs-error_log"

    CustomLog "logs/bbs-access_log"common

</VirtualHost>

 

<VirtualHost *:80>

    ServerAdmin 1198143315@qq.com

    DocumentRoot "/var/html/blog"

    ServerName blog.wangning.com

    ErrorLog "logs/blog-error_log"

    CustomLog "logs/blog-access_log"common

</VirtualHost>

4)配置Apache的主配置文件httpd.conf,將×××部分內(nèi)容前的注釋符井號(hào)去掉

[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末尾添加如下內(nèi)容

<Directory"/var/html">

    Options -Indexes FollowSymLinks

    AllowOverride None

    Order allow,deny

    Allow from all

</Directory>

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

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

 

5)配置Linuxwindows本地hosts文件

linuxhosts文件

[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

WindowsC:\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的瀏覽器里分別訪問三個(gè)域名,大功告成了^*^

Apache-2.2.32安裝配置Apache-2.2.32安裝配置Apache-2.2.32安裝配置

 

三、Apache服務(wù)器的日志格式配置

1.日志格式分為兩種:

通用日志格式(CommonLog  Format

組合日志格式(CombinedLog  Format

默認(rèn)是通用格式,一般工作中習(xí)慣用組合日志

2.設(shè)置三臺(tái)虛擬主機(jī)的日志格式為組合模式

httpd-vhosts.confcommon都改為combined即可

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

<VirtualHost *:80>

    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

</VirtualHost>

 

<VirtualHost *:80>

    ServerAdmin 1198143315@qq.com

    DocumentRoot "/var/html/bbs"

    ServerName bbs.wangning.com

    ErrorLog "logs/bbs-error_log"

    CustomLog "logs/bbs-access_log" combined

</VirtualHost>

 

<VirtualHost *:80>

    ServerAdmin 1198143315@qq.com

    DocumentRoot "/var/html/blog"

    ServerName blog.wangning.com

    ErrorLog "logs/blog-error_log"

    CustomLog "logs/blog-access_log" combined

</VirtualHost>

 

四、Apache服務(wù)器的日志輪詢配置

1.Apache日志輪詢工具有兩種,一種是Apache自帶的輪詢工具rotatelog,另一種是第三方日志輪詢工具cronolog。一般工作中采用第三方工具cronologApache自帶的rotatelog工具之前有過丟日志的情況,所以就一直延續(xù)用第三方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

安裝完后會(huì)生成一個(gè)cronolog命令

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

/usr/local/sbin/cronolog

 

3.配置httpd-vhosts.conf文件,以blog.wangning.com虛擬主機(jī)為例配置,讓access_log日志輪詢(注意日志路徑要寫絕對(duì)路徑)

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

<VirtualHost *:80>

    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

</VirtualHost>

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

blog-access_20170528.log  blog-access_20170627.log

 

五、Apache服務(wù)器的版本號(hào)隱藏配置

1.將full改為Prod,on改為off

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

# ServerTokens

ServerTokens Prod

ServerSignature off

 

2.將×××那行前的注釋符井號(hào)去掉

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

Include conf/extra/httpd-default.conf

 

3.檢查語(yǔ)法,重新加載Apache服務(wù),測(cè)試已無版本號(hào)了

[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

 


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI