RHEL5配置HTTP服務
RHEL5.4配置HTTP 服務下面是關于linux 下面配置HTTP 服務的討論,HTTP 介紹HTTP 的全名為Hyper Text Transfer Protocol(超文本傳輸協(xié)議)在linu
RHEL5.4配置HTTP 服務
下面是關于linux 下面配置HTTP 服務的討論,
HTTP 介紹
HTTP 的全名為Hyper Text Transfer Protocol(超文本傳輸協(xié)議)
在linux 下面實現(xiàn)web 服務,通常使用Apache 來實現(xiàn),Apache 一直是Internet 上面最流行的web 服務器,web 服務器的架設,在linux 下面有個很著名的架構叫l(wèi)amp :linux apache mysql php。
下面是關于HTTP 這個服務的屬性
HTTP 的相關軟件包
Httpd
HTTP 的守護進程
/usr/sbin/httpd
HTTP 的腳本
/etc/init.d/httpd
HTTP 的端口
80(http) 443(https)
HTTP 的配置文件
/etc/http/* /var/www/*
下面來具體搭建HTTP 服務
現(xiàn)在我們主要來實現(xiàn)虛擬主機的搭建,
虛擬主機可以實現(xiàn)在一臺服務器上面運行多個站點,而且之間互不影響。可以大大的節(jié)約成本。虛擬主機技術可以通過三種方式來實現(xiàn):
基于域名,基于IP ,基于端口的虛擬主機。
下面主要討論基于域名的虛擬主機的實現(xiàn),
在實現(xiàn)基于域名的虛擬主機的之前,我們先要在DNS 服務器里面做好解析。 我已經(jīng)為192.168.0.254這個IP 地址做了兩個解析,一個是www1.example.com ,還有一個station1.example.com 。
第一步,安裝軟件包
[root@localhost ~]#
[root@localhost ~]# yum -y install httpd
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Cluster | 1.3 kB 00:00
ClusterStorage | 1.3 kB 00:00
Server | 1.3 kB 00:00
,VT | 1.3 kB 00:00
Setting up Install Process
Resolving Dependencies
There are unfinished transactions remaining. You might consider running
yum-complete-transaction first to finish them.
The program yum-complete-transaction is found in the yum-utils package.
--> Running transaction check
---> Package httpd.i386 0:2.2.3-31.el5 set to be updated
--> Processing Dependency: libapr-1.so.0 for package: httpd
--> Processing Dependency: libaprutil-1.so.0 for package: httpd
--> Running transaction check
---> Package apr.i386 0:1.2.7-11.el5_3.1 set to be updated
---> Package apr-util.i386 0:1.2.7-7.el5_3.2 set to be updated
--> Processing Dependency: libpq.so.4 for package: apr-util
--> Running transaction check
---> Package postgresql-libs.i386 0:8.1.11-1.el5_1.1 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
1.2 M
Installing for dependencies:
apr i386 1.2.7-11.el5_3.1 Server 123 k
apr-util i386 1.2.7-7.el5_3.2 Server 76 k
postgresql-libs i386 8.1.11-1.el5_1.1 Server 196 k
Transaction Summary
================================================================================
Install 4 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
,Total size: 1.6 M
Total download size: 1.2 M
Downloading Packages:
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : apr 1/4
Installing : postgresql-libs 2/4
Installing : apr-util 3/4
Installing : httpd 4/4
Installed:
Dependency Installed:
apr.i386 0:1.2.7-11.el5_3.1 apr-util.i386 0:1.2.7-7.el5_3.2 postgresql-libs.i386 0:8.1.11-1.el5_1.1
Complete!
[root@localhost ~]#
HTTP 軟件包就安裝成功了,
第二步,編輯http 的配置文件
vim /etc/httpd/conf/httpd.conf
這個文件里面的語法很多,我們建議在定義虛擬站點的時候在這個文件的最后編輯,從這個文件的972行開始都是虛擬站點的模板文件,我們可以根據(jù)這些模板文件來定義虛擬站點。
NameVirtualHost 192.168.0.254:80
DocumentRoot /var/www/virt1
ServerName station1. example .com
ServerAlias server1.example .com
DocumentRoot /var/www/virt2
,ServerName www1. example. com
OK ,現(xiàn)在兩個基于域名的虛擬站點基本就配置成功了。
現(xiàn)在,這兩個基于域名的虛擬站點中根目錄還沒有建立,
[root@server1 ~]#
[root@server1 ~]# cd /var/www/
[root@server1 www]# mkdir virt1
[root@server1 www]# mkdir virt2
[root@server1 www]# cd virt1/
[root@server1 virt1]# vim index.html
[root@server1 virt1]# cat index.html
This is station1.example.com webstie!!!
[root@server1 virt1]#
[root@server1 virt1]# cd ../virt2/
[root@server1 virt2]#
[root@server1 virt2]# vim index.html
[root@server1 virt2]# cat index.html
This is www1.example.com website!!!
[root@server1 virt2]#
OK ,這兩個虛擬站點的根目錄就建立,并且還分別建立了一個測試頁面。 首先,重啟下http 服務,
[root@server1 ~]#
[root@server1 ~]# service httpd restart
Stopping httpd: [ OK ] Starting httpd: [ OK ]
[root@server1 ~]#
OK ,服務啟動成功了,測試下。
現(xiàn)在我們到瀏覽器里面輸入station1.example.com
,OK ,頁面顯示正常。
然后在瀏覽器里面輸入www1.example.com
,OK ,顯示也沒有問題。
剛才我們給station1.example.conf 做了一個別名為server1.example.com 。 現(xiàn)在我們來測試下,
最后在瀏覽器里面輸入server1.example.com
,OK ,是和station1這個顯示的相同的內(nèi)容。
關于http 服務的自身的訪問控制
我們可以通過directory 來做權限控制,
在/etc/httpd/conf/httpd.conf文件的虛擬主機之間加入directory 選項。 NameVirtualHost 192.168.0.254:80
DocumentRoot /var/www/virt1
ServerName station1. example .com
ServerAlias server1.example. com
options -Indexes -Followsymlinks
order allow,deny
allow from all
deny from 192.168.0.10
,DocumentRoot /var/www/virt2
ServerName www1. example .com
options -Indexes -Followsymlinks
order deny,allow
deny from all
allow from 192.168.0.10
關于http 服務語法參數(shù)的解釋:
NameVirtualHost 192.168.0.254:80
通告虛擬主機在那個服務器上面以及那個端口,
第一個虛擬主機的站點,
DocumentRoot /var/www/virt1
虛擬主機站點的根目錄,
ServerName station1.example.com
定義虛擬主機站點的域名,
ServerAlias server1.example.com
定義一個虛擬主機域名的別名,
定義虛擬主機站點的訪問控制,
options -Indexes -Followsymlinks
去掉Indexes 和Followsymlinks 的功能,
order allow,deny
allow from all
deny from 192.168.0.10
允許所有,拒絕特定的主機。(這個是有順序的)
order deny,allow
deny from all
allow from 192.168.0.10
拒絕所有,允許特定的主機。(這個是有順序的)
這個是語法,與
這個是語法,與
station1.example.com 這個虛擬站點,拒絕192.168.0.10這臺主機訪問station1.example.com 這個虛擬站點。還定義了拒絕所有主機訪問www1.example.com 這個虛擬站點,允許192.168.0.10這臺主機訪問www1.example.com 這個虛擬站點。
首先,重啟下http 服務,
[root@server1 ~]#
,[root@server1 ~]# service httpd restart
Stopping httpd: [ OK ] Starting httpd: [ OK ]
[root@server1 ~]#
OK ,服務啟動成功了,測試下。
現(xiàn)在我們到192.168.0.10這臺主機上面去測試。
我們到瀏覽器里面輸入
station1.example.com
可以看到,192.168.0.10的確不可以訪問到station1.example.com 這個虛擬站點。 現(xiàn)在我們在到瀏覽器里面輸入www1.example.com
,可以看到,192.168.0.10的確是可以訪問到www1.example.com 這個虛擬站點的。 現(xiàn)在我們在到192.168.0.254上面來測試一下,它應該可以訪問
station1.example.com 這個虛擬站點,應該不可以訪問www1.example.com 。 我們到瀏覽器里面輸入station1.example.com ,