HTTP服务
实验一:
查看默认HTTP使用进程管理方式
更改默认进程管理方式为worker模式
[root@localhost ~]# httpd �Cl //查看进程的管理方式
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、 客户机测试
http://bbs.tarena.com/
http://www.baidu.com/
http://www.google.com/
实验三:基于IP的虚拟主机
服务器上不同的域名对应不同的IP地址
域名 |
IP地址 |
www.tarena.com |
192.168.55.254 |
www.baidu.com |
192.168.55.253 |
www.google.cn |
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 |
www.tarena.com |
8080 |
www.baidu.com |
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、 客户端测试
http://www.tarena.com
http://www.tarena.com:8080/
http://www.tarena.com:8181/