HTTP服務
實驗一:
查看默認HTTP使用進程管理方式
更改默認進程管理方式爲worker模式
[root@localhost ~]# httpd –l //查看進程的管理方式
Compiled in modules:
core.c
prefork.c
http_core.c
mod_so.c
[root@localhost sbin]# mv httpd httpd.prefork //備份源文件
[root@localhost sbin]# mv httpd.worker httpd
啓動服務:
[root@localhost sbin]# service httpd restart
停止 httpd: [確定]
啓動 httpd: [確定]
[root@localhost sbin]# httpd -l
Compiled in modules:
core.c
worker.c
http_core.c
mod_so.c
實驗二:基於域名的虛擬主機
當用戶訪問www.baidu.com的時候訪問baidu網站
當用戶訪問www.google.com的時候訪問google網站
baidu和google的ip地址一樣
確保上面www.tarena.com訪問還能訪問
1、 前提條件:
客戶端hosts文件或DNS
Hosts文件:192.168.55.254 www.tarena.com
192.168.55.253 www.baidu.com
192.168.55.252 www.google.cn
2、 建立網站存放的路徑
[root@localhost ~]# mkdir /data/web/baidu/
[root@localhost ~]# mkdir /data/web/google/
[root@localhost ~]# vim /data/web/baidu/index.html
<html>
<head><title>baidu</title>
<body><h1>this is www.baidu.com </h1>
<hr></hr>
</body>
</head>
</html>
[root@localhost ~]# vim /data/web/google/index.html
<html>
<head><title>google.com</title>
<body><h1>this is www.google.com</h1>
</body>
</head>
</html>
3、 修改主配置文件
[root@localhost ~]# vim /etc/httpd/conf.d/virt.conf
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/html/
ServerNamewww.tarena.com
ErrorLog logs/tarena.com-error_log
CustomLog logs/tarenae.com-access_log common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /data/web/baidu
ServerName www.baidu.com
ErrorLog logs/baidu.com-error_log
CustomLog logs/baidu.com-access_log common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /data/web/google
ServerName www.google.com
ErrorLog logs/google.com-error_log
CustomLog logs/google.com-access_log common
</VirtualHost>
4、 啓動服務
[root@localhost ~]# service httpd restart
[root@localhost ~]# chkconfig httpd on
5、 客戶機測試
實驗三:基於IP的虛擬主機
服務器上不同的域名對應不同的IP地址
域名 | IP地址 |
192.168.55.254 | |
192.168.55.253 | |
192.168.55.252 |
1、 設置IP地址
[root@localhost ~]# vim/etc/sysconfig/network-scripts/接口1
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
HWADDR=00:0c:29:c2:46:af
IPADDR=192.168.55.254
NETMASK=255.255.255.0
[root@localhost ~]# cat /etc/sysconfig/network-scripts/接口2
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0:0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.55.253
NETMASK=255.255.255.0
[root@localhost ~]# cat /etc/sysconfig/network-scripts/接口3
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0:1
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.55.252
NETMASK=255.255.255.0
2、 建立網站存放路徑
略……(參考上一實驗)
3、 修改主配置文件
[root@localhost ~]# vim /etc/httpd/conf.d/virt.conf
<VirtualHost 192.168.55.254:80>
DocumentRoot /var/www/html/
ServerName www.tarena.com
ErrorLog logs/tarena.com-error_log
CustomLog logs/tarenae.com-access_log common
</VirtualHost>
<VirtualHost 192.168.55.253:80>
DocumentRoot /data/web/baidu
ServerName www.baidu.com
ErrorLog logs/baidu.com-error_log
CustomLog logs/baidu.com-access_log common
</VirtualHost>
<VirtualHost 192.168.55.252:80>
DocumentRoot /data/web/google
ServerName www.google.com
ErrorLog logs/google.com-error_log
CustomLog logs/google.com-access_log common
</VirtualHost>
4、 啓動服務
[root@localhost ~]# service httpd restart
[root@localhost ~]# chkconfig httpd on
5、 客戶機測試
http://192.168.55.254/http://www.tarena.com/
http://192.168.55.253/http://www.baidu.com/
http://192.168.55.252/http://www.google.com/
實驗四:基於端口的虛擬主機
不同的域名對應不同的端口
端口 | 域名 |
80 | |
8080 | |
8181 | www.google.cn |
1、 建立站點存放路徑
略…….
2、 修改配置文件
[root@localhost ~]# cat /etc/httpd/conf.d/virt.conf
<VirtualHost *:80>
DocumentRoot /var/www/html/
ServerName www.tarena.com
ErrorLog logs/tarena.com-error_log
CustomLog logs/tarenae.com-access_log common
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot /data/web/baidu
ServerName www.baidu.com
ErrorLog logs/baidu.com-error_log
CustomLog logs/baidu.com-access_log common
</VirtualHost>
<VirtualHost *:8181>
DocumentRoot /data/web/google
ServerName www.google.com
ErrorLog logs/google.com-error_log
CustomLog logs/google.com-access_log common
</VirtualHost>
3、 啓動服務
[root@localhost ~]# service httpd restart
[root@localhost ~]# chkconfig httpd on
4、 客戶端測試