Apache-2.2.32安裝配置-創(chuàng)新互聯(lián)

Apache-2.2.32安裝配置

創(chuàng)新互聯(lián)從2013年成立,先為衢州等服務(wù)建站,衢州等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為衢州企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

一、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.檢查語法,啟動Apache服務(wù),兩種啟動方法

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

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

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服務(wù)

在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服務(wù)是否正常啟動

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

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

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

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

[root@apache htdocs]# pwd

/application/apache/htdocs

2.修改默認(rèn)首頁為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     ###測試修改首頁成功

www.wangning.com

3.當(dāng)默認(rèn)首頁不存在的時候,Apache服務(wù)默認(rèn)會在瀏覽器頁面顯示目錄結(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前面加上一個減號,或者將 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ī)(基于域名、端口號、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     ###在這三個目錄里分別創(chuàng)建一個index.html文件,并寫入三個網(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)容,并把文件里兩個默認(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)容前的注釋符井號去掉

[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)配置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服務(wù)器的日志格式配置

1.日志格式分為兩種:

通用日志格式(CommonLog Format)

組合日志格式(CombinedLog Format)

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

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

將httpd-vhosts.conf中common都改為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。一般工作中采用第三方工具cronolog,Apache自帶的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

安裝完后會生成一個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日志輪詢(注意日志路徑要寫絕對路徑)

[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ù)器的版本號隱藏配置

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服務(wù),測試已無版本號了

[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

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

網(wǎng)頁標(biāo)題:Apache-2.2.32安裝配置-創(chuàng)新互聯(lián)
網(wǎng)站地址:http://www.bm7419.com/article8/cdjjip.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、網(wǎng)站制作、搜索引擎優(yōu)化、關(guān)鍵詞優(yōu)化、網(wǎng)站營銷云服務(wù)器

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設(shè)計公司