Apache-2.2.32安裝配置
Apache-2.2.32安裝配置
一、Apache服務安裝
1.創建目錄,下載Apache源碼包
[[email protected] ~]# mkdir/home/wangning/tools -p
[[email protected] ~]# cd/home/wangning/tools
[[email protected] tools]# wgethttp://mirror.bit.edu.cn/apache/httpd/httpd-2.2.32.tar.gz
2.解壓,安裝Apache
[[email protected] tools]# tar zxvfhttpd-2.2.32.tar.gz
[[email protected] tools]# cdhttpd-2.2.32
[[email protected] httpd-2.2.32]# yum-y install zlib zlib-devel ###安裝zlib依賴包
[[email protected] 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
[[email protected] httpd-2.2.32]#make
[[email protected] httpd-2.2.32]#make install
[[email protected] httpd-2.2.32]# ln-s /application/apache2.2.32//application/apache
3.檢查語法,啟動Apache服務,兩種啟動方法
[[email protected] httpd-2.2.32]#/application/apache/bin/apachectl -t
[[email protected]
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)
[[email protected] httpd-2.2.32]#/application/apache/bin/httpd -k start ###啟動Apache服務
在hosts文件裏添加黃色部分,報錯1消除
[[email protected] ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4localhost4.localdomain4
::1 localhost localhost.localdomainlocalhost6 localhost6.localdomain6
10.0.0.20 apache
在配置文件裏添加黃色部分,報錯2消除
[[email protected] ~]# 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服務是否正常啟動
[[email protected] httpd-2.2.32]#lsof -i:80
[[email protected] httpd-2.2.32]# ps-ef|grep httpd
[[email protected] httpd-2.2.32]#curl 127.0.0.1 ###測試瀏覽器是否可以訪問
<html><body><h1>Itworks!</h1></body></html>
二、Apache服務器的首頁,結構目錄和虛擬主機配置
1.默認首頁所在的目錄,默認首頁為index.html
[[email protected] htdocs]# pwd
/application/apache/htdocs
2.修改默認首頁為wangning.html,黃色為增加的內容
[[email protected] conf]# grepDirectoryIndex /application/apache/conf/httpd.conf
# DirectoryIndex: sets the filethat Apache will serve if a directory
DirectoryIndex wangning.html index.html
[[email protected] htdocs]# touch/application/apache/htdocs/wangning.html
[[email protected] htdocs]# echo"www.wangning.com" >/application/apache/htdocs/wangning.html
[[email protected] htdocs]# ls/application/apache/htdocs
index.html wangning.html
[[email protected] htdocs]#/application/apache/bin/apachectl -t
[[email protected] htdocs]# /application/apache/bin/apachectl graceful
[[email protected] htdocs]# curl10.0.0.20 ###測試修改首頁成功
www.wangning.com
3.當默認首頁不存在的時候,Apache服務默認會在瀏覽器頁面顯示目錄結構
[[email protected] htdocs]# cd/application/apache/htdocs/
[[email protected] htdocs]# mv index.htmlindex.html.bak
在瀏覽器中輸入Apache服務器地址,默認是顯示目錄結構的
在配置文件中Indexes前面加上一個減號,或者將 Indexex刪掉,就不顯示目錄結構了
[[email protected] 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
[[email protected] htdocs]# /application/apache/bin/apachectl -t
[[email protected] htdocs]#/application/apache/bin/apachectl graceful
這樣就不顯示目錄結構了
4.配置Apache服務器的虛擬主機(基於域名、端口號、ip)
1) 基本信息如下
域名 | 站點目錄 |
www.wangning.com | /var/html/www |
bbs.wangning.com | /var/html/bbs |
blog.wangning.com | /var/html/blog |
2)創建站點目錄
[[email protected] /]# mkdir/var/html/{www,bbs,blog} -p
[[email protected] /]# for n in wwwbbs blog;do echo "http://$n.wangning.com">/var/html/$n/index.html;done ###在這三個目錄裏分別創建一個index.html文件,並寫入三個網址
[[email protected] /]# 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)在虛擬主機配置文件末尾增加以下內容,並把文件裏兩個默認的虛擬主機樣例刪掉
[[email protected] /]# cat/application/apache/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin [email protected]
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 [email protected]
DocumentRoot "/var/html/bbs"
ServerName bbs.wangning.com
ErrorLog "logs/bbs-error_log"
CustomLog "logs/bbs-access_log"common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/html/blog"
ServerName blog.wangning.com
ErrorLog "logs/blog-error_log"
CustomLog "logs/blog-access_log"common
</VirtualHost>
4)配置Apache的主配置文件httpd.conf,將黃色部分內容前的註釋符井號去掉
[[email protected] /]# 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末尾添加如下內容
<Directory"/var/html">
Options -Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
[[email protected] /]#/application/apache/bin/apachectl -t
[[email protected] /]#/application/apache/bin/apachectl graceful
5)配置Linux和windows本地hosts文件
linux的hosts文件
[[email protected] /]# 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服務器的日誌格式配置
1.日誌格式分為兩種:
通用日誌格式(CommonLog Format)
組合日誌格式(CombinedLog Format)
默認是通用格式,一般工作中習慣用組合日誌
2.設置三臺虛擬主機的日誌格式為組合模式
將httpd-vhosts.conf中common都改為combined即可
[[email protected] ~]# cat /application/apache/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin [email protected]
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 [email protected]
DocumentRoot "/var/html/bbs"
ServerName bbs.wangning.com
ErrorLog "logs/bbs-error_log"
CustomLog "logs/bbs-access_log" combined
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/html/blog"
ServerName blog.wangning.com
ErrorLog "logs/blog-error_log"
CustomLog "logs/blog-access_log" combined
</VirtualHost>
四、Apache服務器的日誌輪詢配置
1.Apache日誌輪詢工具有兩種,一種是Apache自帶的輪詢工具rotatelog,另一種是第三方日誌輪詢工具cronolog。一般工作中采用第三方工具cronolog,Apache自帶的rotatelog工具之前有過丟日誌的情況,所以就一直延續用第三方cronolog日誌工具
2.下載並編譯安裝日誌輪詢cronolog工具
[[email protected] tools]# wgethttp://down1.chinaunix.net/distfiles/cronolog-1.6.2.tar.gz
[[email protected] tools]# tar zxvfcronolog-1.6.2.tar.g
[[email protected] tools]# cdcronolog-1.6.2
[[email protected] cronolog-1.6.2]#./configure
[[email protected] cronolog-1.6.2]#make
[[email protected] cronolog-1.6.2]#make install
安裝完後會生成一個cronolog命令
[[email protected] cronolog-1.6.2]#ls /usr/local/sbin/cronolog
/usr/local/sbin/cronolog
3.配置httpd-vhosts.conf文件,以blog.wangning.com虛擬主機為例配置,讓access_log日誌輪詢(註意日誌路徑要寫絕對路徑)
[[email protected] /]# cat/application/apache/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin [email protected]
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>
[[email protected] /]# ls /app/logs/ ###顯示配置成功
blog-access_20170528.log blog-access_20170627.log
五、Apache服務器的版本號隱藏配置
1.將full改為Prod,on改為off
[[email protected] ~]# egrep"ServerTokens|ServerSignature" /application/apache/conf/extra/httpd-default.conf
# ServerTokens
ServerTokens Prod
ServerSignature off
2.將黃色那行前的註釋符井號去掉
[[email protected] ~]# grep "Includeconf/extra/httpd-default.conf" /application/apache2.2.32/conf/httpd.conf
Include conf/extra/httpd-default.conf
3.檢查語法,重新加載Apache服務,測試已無版本號了
[[email protected] ~]#/application/apache/bin/apachectl -t
[[email protected] ~]#/application/apache/bin/apachectl graceful
[[email protected] ~]# 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
本文出自 “飛奔的駱駝” 博客,請務必保留此出處http://wn2100.blog.51cto.com/9915310/1942740
Apache-2.2.32安裝配置