实战-源码编译搭建LAMP环境

实战内容:搭建一个虚拟主机,并且演示三种不同情况的浏览效果

1.开启虚拟主机

实战-源码编译搭建LAMP环境

2.

方法1:通过不同的IP地址,解析不同域名

给服务器增加IP(另一个域名解析出来的那个IP)。

 

[root@xuegod60 conf]# ifconfigeth0:1 192.168.10.90 netmask 255.255.255.0 #添加一个ip

[root@xuegod60 conf]# mkdir -p/var/www/html/bbs                   #创建一个bbs目录

[root@xuegod60 conf]# echo"bbs.192.168.10.90" >/var/www/html/bbs/index.html

[root@xuegod60 conf]# ping192.168.10.90

PING 192.168.10.90(192.168.10.90) 56(84) bytes of data.

64 bytes from 192.168.10.90:icmp_seq=1 ttl=64 time=0.042 ms

 

 

修改httpd.conf

#vim httpd.conf   在文件的最后,添加以下内容

<VirtualHost192.168.10.60:80>

    ServerAdminwebmaster@dummy-host.example.com

    DocumentRoot/var/www/html/

    ServerNamedummy-host.example.com

    ErrorLoglogs/dummy-host.example.com-error_log

    CustomLoglogs/dummy-host.example.com-access_log common

</VirtualHost>

<VirtualHost 192.168.10.90:80>

    ServerAdminwebmaster@dummy-host.example.com

    DocumentRoot/var/www/html/bbs/

    ServerNamedummy-host.example.com

    ErrorLoglogs/dummy-host.example.com-error_log

    CustomLoglogs/dummy-host.example.com-access_log common

</VirtualHost>

测试:

[root@xuegod60 conf]# service httpd restart

http://192.168.10.60/

实战-源码编译搭建LAMP环境

http://192.168.10.90/

实战-源码编译搭建LAMP环境

 

 

方法二:通过不同域名:

在域名管理后台,修改DNS配置,www.xuegod.com与bbs.xuegod.com解析成相同的IP。

 

修改httpd.conf

#vim httpd.conf

<VirtualHost *:80>

    ServerAdminwebmaster@dummy-host.example.com

    DocumentRoot/var/www/html/

    ServerName www.xuegod.com

    ErrorLog logs/www.xuegod.com-error_log

    CustomLog logs/www.xuegod.com-access_logcommon

</VirtualHost>

<VirtualHost *:80>

    ServerAdminwebmaster@dummy-host.example.com

    DocumentRoot /var/www/html/bbs/

ServerName  bbs.xuegod.com

ErrorLog logs/bbs.xuegod.com-error_log

    CustomLog logs/bbs.xuegod.com-access_log common

</VirtualHost>

 

在windows下windows  hosts文件在:   C:\Windows\System32\drivers\etc

192.168.10.60 www.xuegod.com

192.168.10.60 bbs.xuegod.com

测试:

[root@xuegod60 conf]# servicehttpd restart

 

www.xuegod.com

实战-源码编译搭建LAMP环境

 

bbs.xuegod.com

实战-源码编译搭建LAMP环境

 

方法3:基于端口配置虚拟主机:

[root@xuegod60 conf]# vim /etc/httpd/conf/httpd.conf  

添加90端口

实战-源码编译搭建LAMP环境
 

<VirtualHost *:80>

    ServerAdminwebmaster@dummy-host.example.com

    DocumentRoot/var/www/html/

    ServerNamewww.example.com

    ErrorLoglogs/www.example.com-error_log

    CustomLoglogs/www.example.com-access_log common

</VirtualHost>

<VirtualHost *:90>

    ServerAdminwebmaster@dummy-host.example.com

    DocumentRoot/var/www/html/bbs/

    ServerNamebbs.example.com

    ErrorLoglogs/bbs.example.com-error_log

    CustomLoglogs/bbs.example.com-access_log common

</VirtualHost>

 

测试:

[root@xuegod60 conf]# service httpd restart

http://192.168.10.60/

实战-源码编译搭建LAMP环境

 

http://192.168.10.60:90

实战-源码编译搭建LAMP环境

上一篇:菜鸟笔记 -- Chapter 6.2.4 成员方法


下一篇:MySQL备份还原之Navicat Premium实现