httpd基于ip、port、domain三种方式的VirtualHost

简介:

本机IP  eth0:192.168.244.150 eth0:0 192.168.244.158

1、基于相同IP不同port的VirtualHost

编辑httpd.conf新增配置项

vim /etc/httpd/conf/httpd.conf

1
2
Listen  8080
Listen  8888

在最下列新增

1
2
3
4
5
6
<VirtualHost  192.168 . 244.150 : 8080 >
DocumentRoot / var /www/html/website1
</VirtualHost>
<VirtualHost  192.168 . 244.150 : 8888 >
DocumentRoot / var /www/html/website2
</VirtualHost>

创建目录:

mkdir /var/www/html/website1

mkdir /var/www/html/website2

echo website1 > /var/www/html/website1

echo website2 > /var/www/html/website2

重启服务: /etc/init.d/httpd restart

浏览器浏览测试

测试正常

2、基于相同port不同ip的VirtualHost

新增IP

ifconfig eth0:0 192.168.244.158

编辑httpd.conf新增配置项

vim /etc/httpd/conf/httpd.conf

1
2
3
4
5
6
<VirtualHost  192.168 . 244.150 : 8888 >
DocumentRoot / var /www/html/website1
</VirtualHost>
<VirtualHost  192.168 . 244.158 : 8888 >
DocumentRoot / var /www/html/website2
</VirtualHost>

显示内容同上,因为DocumentRoot路径一样

/etc/init.d/httpd restart

同时打开两个浏览器进行测试

测试OK

3、基于相同IP相同port不同domain的VirtualHost

编辑httpd.conf新增配置项

vim /etc/httpd/conf/httpd.conf

1
2
3
4
5
6
7
8
9
NameVirtualHost  192.168 . 244.150
<VirtualHost www.lansgg1.com>
DocumentRoot / var /www/html/website1
ServerName      www.lansgg1.com
</VirtualHost>
<VirtualHost www.lansgg2.com>
DocumentRoot / var /www/html/website2
ServerName      www.lansgg2.com
</VirtualHost>

重启httpd

/etc/init.d/httpd restart

修改本地hosts

1
2
192.168 . 244.150  www.lansgg1.com
192.168 . 244.150  www.lansgg2.com

进行基于域名测试

测试OK!!



本文转自 西索oO 51CTO博客,原文链接:http://blog.51cto.com/lansgg/1213670

相关文章
|
9月前
|
网络协议 应用服务中间件 nginx
解决 nginx 启动错误host not found in upstream "XXXX.com“
在前置机上利用nginx进行反向代理的时候,我们会配置proxy_pass。在启动nginx的会报如下错误:host not found in upstream "XXXX.com“
4418 0
|
Linux 网络安全
ssh: connect to host 10.13.69.163 port 22: No route to host
ssh: connect to host 10.13.69.163 port 22: No route to host
|
关系型数据库 MySQL Unix
nginx代理DB & ip限制
nginx代理DB & ip限制
344 0
|
机器学习/深度学习 网络协议 决策智能
ubuntu16.04中 启动 Error starting userland proxy: listen tcp 0.0.0.0:5900: bind: address already in use
ubuntu16.04中 启动 Error starting userland proxy: listen tcp 0.0.0.0:5900: bind: address already in use
184 0
|
缓存 调度 容器
【Agones系列】Game Server的地址与端口
本文介绍Agones的网络模式,如何分配服务地址与端口
【Agones系列】Game Server的地址与端口
Node:http-server开启静态服务器
Node:http-server开启静态服务器
122 0
|
安全 网络协议 算法
RH358配置Web服务器--使用 Apache HTTPD 配置 HTTPS
RH358配置Web服务器--使用 Apache HTTPD 配置 HTTPS
264 0
RH358配置Web服务器--使用 Apache HTTPD 配置 HTTPS
|
网络协议
localhost与ip的区别
localhost与ip的区别
578 0
localhost与ip的区别
|
Web App开发 应用服务中间件 nginx