目錄
- http簡(jiǎn)介
1.1 關(guān)于http協(xié)議
1.2 服務(wù)器實(shí)現(xiàn)的思路 - 搭建http服務(wù)器
1. http簡(jiǎn)介
1.1 關(guān)于http協(xié)議
即超文本傳輸協(xié)議,是互聯(lián)網(wǎng)上應(yīng)用最廣泛的網(wǎng)絡(luò)協(xié)議。它是應(yīng)用層的協(xié)議,底層是基于TCP協(xié)議通信的。HTTP協(xié)議的工作過程:客戶通過瀏覽器向服務(wù)器發(fā)送文檔請(qǐng)求,瀏覽器將請(qǐng)求的資源回應(yīng)給瀏覽器,然后關(guān)閉連接。即:連接->請(qǐng)求->響應(yīng)->關(guān)閉連接。
1.2 服務(wù)器實(shí)現(xiàn)的思路
(1)http是基于TCP協(xié)議通信,實(shí)現(xiàn)web服務(wù)器的第一步是實(shí)現(xiàn)兩臺(tái)機(jī)器之間不同進(jìn)程之間的通信。
(2)通過瀏覽器向服務(wù)器發(fā)送請(qǐng)求,發(fā)送http請(qǐng)求報(bào)文
(3)收到請(qǐng)求數(shù)據(jù)之后,服務(wù)器解析,服務(wù)器就知道了客戶端的要求
(4)判斷資源是否存在,存在,判斷資源是目錄、文件、可執(zhí)行程序,獲取目錄hello/index.html文件.服務(wù)器讀取文件內(nèi)容發(fā)送給瀏覽器;不存在,服務(wù)器需要返回給瀏覽器一個(gè)默認(rèn)的404頁面,告訴客戶請(qǐng)求的資源不存在。
2. 搭建http服務(wù)器
(1)檢查/etc/hosts文件
[root@oraclehost ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
地址解析文件,將要訪問的地址和域名添加進(jìn)去
[root@oraclehost ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.56.12 oraclehost
192.168.3.88 cuug
(2)安裝http包
兩種方法:
1)下載Apache軟件,2)RHEL光盤
我們采用第二種,光盤安裝。首先“插入”ISO鏡像光盤
查看Linux下是否安裝http服務(wù)(缺省沒有安裝http包)
[root@oraclehost ~]# rpm -qa |grep http
httpd-tools-2.2.15-59.el6.x86_64
httpd-2.2.15-59.el6.x86_64
掛載光盤,安裝http包
[root@oraclehost ~]# mount /dev/sr0 /mnt
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@oraclehost ~]# yum -y install http*
Complete!
[root@oraclehost ~]# rpm -qa |grep http
httpd-devel-2.2.15-59.el6.x86_64
httpd-tools-2.2.15-59.el6.x86_64
httpd-2.2.15-59.el6.x86_64
httpd-manual-2.2.15-59.el6.noarch
啟動(dòng)http服務(wù),并查看端口號(hào)(默認(rèn)80)
[root@oraclehost ~]# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully
qualified domain name, using 192.168.56.12 for ServerName
[ OK ]
[root@oraclehost ~]# netstat -an |grep :80
tcp 0 0 :::80 :::* LISTEN
/etc/httpd/conf/httpd.conf是http的配置文件,缺省下無需修改
將HTML文件放到指定的目錄中/var/www/html
[root@oraclehost ~]# cp *.html /var/www/html
Windows客戶端IE瀏覽器查看
顯示結(jié)果: