apache服务器基于ip以及基于端口的虚拟主机访问

一.基于ip地址的访问

1 在apache服务器配置文件中的最后添加新配置文件

vi /etc/httpd/conf/http.conf

Include vhost/vhost.conf  #vhost/vhost.conf 为新文件的相对路径,vhost.conf为新建配置文件

2 编写配置文件vhost.conf

 1 <VirtualHost 192.168.1.10:80>
2   ServerAdmin webmaster@dummy-host.example.com
3   DocumentRoot /data/web/test01  #访问页面相对路径
4   ServerName dummy-host.example.com
5   ErrorLog logs/dummy-host.example.com-error_log #日志文件路径
6   CustomLog logs/dummy-host.example.com-access_log common
7 </VirtualHost>
8 <VirtualHost 192.168.1.20:80>
9   ServerAdmin webmaster@dummy-host.example.com
10   DocumentRoot /data/web/test02 #访问页面路径
11   ServerName dummy-host.example.com
12   ErrorLog logs/dummy-host.example.com-error_log
13   CustomLog logs/dummy-host.example.com-access_log common
14 </VirtualHost>

3 配置虚拟网卡

ifconfig eth0:0 192.168.1.10 up

ifconfig eth0:0 192.168.1.20 up

4 重启 apache服务

service httpd restart

访问:192.168.1.10

     192.168.1.20

 

 

二 基于端口的访问

1 在apache服务器配置文件中的最后添加新配置文件

vi /etc/httpd/conf/http.conf

Include vhost/vhost.conf  #vhost/vhost.conf 为新文件的相对路径,vhost.conf为新建配置文件

2 编写要添加的配置文件

Listen 81 #开启端口 默认端口是80
Listen 82 #开启端口
<VirtualHost 192.168.1.99:81> # 192.168.1.99是本机ip
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /data/web/test01 #页面路径
ServerName dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
<VirtualHost 192.168.1.99:82>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /data/web/test02
ServerName dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>

3 重启apache服务器

service httpd restart

4 访问 192.168.1.99:81

    192.168.1.99:82


转载于:https://www.cnblogs.com/loveCloud/archive/2012/01/29/2331058.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值