0
点赞
收藏
分享

微信扫一扫

APACHE-虚拟主机-基于端口的虚拟主机

APACHE-虚拟主机-基于端口的虚拟主机


一个服务器发布多个网站三种有方法


默认网站与虚拟主机不能用时存在


一个网站在网络中需要三个条件:

1.监听IP

2.监听端口port

3.监听域名


实施

一、基于端口的虚拟主机 (我的本机IP 10.10.201.159)

我的apache安装在/usr/local/apache


1.修改主配置文件httpd.conf

vim /usr/local/apache/conf/httpd.conf


下面去掉注释#大概在480行

Include conf/extra/httpd-vhosts.conf


2.建立2个静态网站网站

mkdir /usr/local/apache/htdocs/web1  为网站1的家里主目录

mkdir /usr/local/apache/htdocs/web2  为网站2的家里主目录


echo WEB1 >   /usr/local/apache/htdocs/web1/index.html   网站1的内容显示WEB1

echo WEB2 >  /usr/local/apache/htdocs/web2/index.html   网站2的内容显示WEB2


3.设置子配置文件 httpd-vhosts.conf


vim /usr/local/apache/conf/extra/httpd-vhosts.conf  


默认给了两个示例 可以全部注释掉 改成下面的

或者直接在示例中VirtualHost 更改为自己的IP地址DocumentRoot 改为自己的网站目录 一个WEB1的 另外一个WEB2的


<VirtualHost *:80>

  # ServerAdmin webmaster@dummy-host.example.com

   DocumentRoot "/usr/local/apache/htdocs/web1"

  # ServerName dummy-host.example.com

  # ServerAlias www.dummy-host.example.com

   ErrorLog "logs/dummy-host.example.com-error_log"

   CustomLog "logs/dummy-host.example.com-access_log" common

</VirtualHost>


Listen 81

<VirtualHost *:81>

  # ServerAdmin webmaster@dummy-host2.example.com

   DocumentRoot "/usr/local/apache/htdocs/web2"

  # ServerName dummy-host2.example.com

   ErrorLog "logs/dummy-host2.example.com-error_log"

   CustomLog "logs/dummy-host2.example.com-access_log" common

</VirtualHost>



4.测试配置文件 正确性


cd /usr/local/apache/bin/

./apachectl -t


显示 以下为正确

Syntax OK


5.重启动apache

killall httpd    关闭apache

./apachectl     启动apache

lsof -i :80        查看httpd是否启动80端口

lsof -i :81       查看httpd是否启动81端口



6.完成 浏览器 访问 测试或者工具测试


yum -y install elinks  安装一个本机测试工具


[root@localhost bin]# elinks http://10.10.201.159 --dump

  WEB1

[root@localhost bin]# elinks http://10.10.201.159:81 --dump

  WEB2

[root@localhost bin]#

举报

相关推荐

0 条评论