WWW服務(wù)
1、www(World wide web,全球信息網(wǎng)),是構(gòu)建在Internet基礎(chǔ)之上的,以WEB服務(wù)作為表現(xiàn)形式的一種邏輯網(wǎng)絡(luò)。
2、WEB服務(wù)的實(shí)現(xiàn)程序:MS IIS、Apache、SunONE、NCSA httpd
安裝Apache
1、安裝包結(jié)構(gòu)
httpd-2.2.3-6.el5.i386.rpm 主程序
httpd-manual-2.2.3-6.el5.i386.rpm Apache手冊(cè)
httpd-devel-2.2.3-6.el5.i386.rpm 開(kāi)發(fā)庫(kù)
system-config-httpd-1.3.3.1-1.el5.noarch.rpm 圖形配置工具
2、啟動(dòng)Apache 測(cè)試安裝:服務(wù)名httpd
3、配置文件/etc/httpd/conf/httpd.conf
Apache服務(wù)的配置與管理
一、Apache服務(wù)的基本配置
1、配置文件/etc/httpd/conf/httpd.conf
結(jié)構(gòu):Section 1: Global Environment(全局配置)
Section 2: 'Main' server configuration(主服務(wù)器配置)
Section 3: Virtual Hosts (虛擬主機(jī)配置)
二、Apache的基本配置
1、設(shè)置Apache的主目錄
279 DocumentRoot "/var/www/html"
DocumentRoot “Apache的主目錄絕對(duì)路徑”
2、設(shè)置Apache的主頁(yè)文件
390 DirectoryIndex index.html index.html.var
DirectoryIndex 順序1文件 順序2文件 ...... 順序n文件
3、設(shè)置Apache服務(wù)的監(jiān)聽(tīng)端口
134 Listen 80 監(jiān)聽(tīng)本機(jī)上所有IP的80端口
Listen IP:端口號(hào) 監(jiān)聽(tīng)本機(jī)特定IP的特定端口
在Apache中可以使用多條Listen命令實(shí)現(xiàn)多主機(jī)與多端口的靈活配置。
4、設(shè)置Apache的相對(duì)根目錄:
a、相對(duì)根目錄是Aapache程序文件的存放位置,包括配置文件和日志文件。
b、57 ServerRoot "/etc/httpd"
5、設(shè)置Apache的日志文件:
a、日志的種類:錯(cuò)誤日志
訪問(wèn)日志
b、錯(cuò)誤日志:471 ErrorLog logs/error_log
ErrotLog 錯(cuò)誤日志文件名
c、訪問(wèn)日志:513 CustomLog logs/access_log combined
CustomLog 訪問(wèn)日志文件名 訪問(wèn)日志的格式
訪問(wèn)日志格式:common(標(biāo)準(zhǔn)格式,為絕大多數(shù)日志分析工具所識(shí)別)
combined (common的擴(kuò)展)
日志格式由484 LogFormat 命令定義
6、管理員地址設(shè)置,Apache故障時(shí)的通知地址。
250 ServerAdmin root@localhost
7、設(shè)置Apache服務(wù)所在主機(jī)的主機(jī)名:Apache啟動(dòng)時(shí)會(huì)向DNS解析主機(jī)名
263 ServerName www.itatpro.com:80
ServerName 主機(jī)的FQDN:端口號(hào)
ServerName IP:端口號(hào)
三、設(shè)置用戶主目錄權(quán)限
304 Directory "/var/www/html"
Directory "用戶主目錄"
318 Options Indexes FollowSymLinks MultiViews
選項(xiàng) 允許目錄瀏覽 允許多重視圖
-Indexes 不允許目錄瀏覽
多重視圖 Apache會(huì)自動(dòng)匹配相近的內(nèi)容回傳客戶端,支持符
號(hào)連接文件的使用。
325 AllowOverride None(禁止使用每個(gè)目錄下的.htaccess文件實(shí)現(xiàn)訪問(wèn)控制)
330 Order allow,deny(訪問(wèn)控制)
331 Allow from all
Order 允許,禁止
允許 from 所有
Order 優(yōu)先級(jí)2,優(yōu)先級(jí)1
allow from IP 允許訪問(wèn)的地址
deny from IP 禁止訪問(wèn)的地址
333 /Directory
四、創(chuàng)建虛擬目錄
1、虛擬目錄:是主目錄的擴(kuò)充。虛擬目錄可以靈活的配置磁盤(pán)空間。
2、添加虛擬目錄:
Alias /虛擬目錄名/ "虛擬目錄的實(shí)際位置"
Directory "虛擬目錄的實(shí)際位置"
541 Options Indexes MultiViews
542 AllowOverride None
543 Order allow,deny
544 Allow from all
545 /Directory
3、絕對(duì)引用
Alias /虛擬目錄名(/) "/虛擬目錄的實(shí)際位置(/)"
五、訪問(wèn)控制
1、用戶身份驗(yàn)證
a、建立口令文件與添加安全帳戶
#htpasswd -c /口令文件存儲(chǔ)位置 安全帳戶名
-c 創(chuàng)建口令文件
b、配置用戶驗(yàn)證(目錄權(quán)限設(shè)置領(lǐng)域)
AuthType Basic (用戶認(rèn)證類型 基本認(rèn)證)
AuthName "This is a security Site,Please Login:"(用戶認(rèn)證領(lǐng)域內(nèi)容)
AuthUserFile /etc/httpd/passwd01 (用戶口令文件的位置)
Require user root tom (允許訪問(wèn)的用戶)
六、虛擬主機(jī)
1、基于IP的虛擬主機(jī)
a、確定主機(jī)的IP地址:
新建虛擬接口:#ifconfig eth0:1 IP地址
b、創(chuàng)建基于IP的虛擬主機(jī)
VirtualHost 192.168.16.252
ServerName 192.168.16.252:80 設(shè)置主機(jī)名
ServerAdmin [email protected] 管理員郵件地址
DocumentRoot "/www/itat" 主目錄
DirectoryIndex index.html 主頁(yè)文件
Errorlog logs/itat/error_log 錯(cuò)誤日志
Customlog logs/itat/access_log common 訪問(wèn)日志
AuthType Basic
AuthName "This is a security Site,Please Login:"
AuthUserFile /etc/httpd/passwd01
Require user root tom
/VirtualHost
2、基于端口的虛擬主機(jī)
VirtualHost *:8081 (*表示本機(jī)的所有IP地址)
ServerName 192.168.16.254:8081
......
/VirtualHost
3、基于多主機(jī)頭的虛擬主機(jī)(所有站點(diǎn)均應(yīng)包含在虛擬主機(jī)設(shè)置中)
a、創(chuàng)建DNS解析結(jié)構(gòu)
b、創(chuàng)建基于主機(jī)頭的虛擬主機(jī)
例:NameVirtualHost 192.168.16.254 (設(shè)置不同主機(jī)頭所公用的IP)
VirtualHost www.itat.com(第一個(gè)虛擬主機(jī)為默認(rèn)虛擬主機(jī),承擔(dān)所有對(duì)本
ServerName www.itat.com:80 Apache非指定主機(jī)頭的訪問(wèn))
ServerAdmin [email protected]
DocumentRoot "/www/itat"
DirectoryIndex index.html
Errorlog logs/itat/error_log
Customlog logs/itat/access_log common
/VirtualHost
VirtualHost www.baidu.com
ServerName www.baidu.com:80
ServerAdmin [email protected]
DocumentRoot "/www/baidu"
DirectoryIndex index.html
Errorlog logs/baidu/error_log
Customlog logs/baidu/access_log common
/VirtualHost
新聞熱點(diǎn)
疑難解答
圖片精選