搭建基于ip地址对web服务器的访问

要求

一个ip对应一个网。例如实现以下操作:
建立一个192.168.19.102的网站 ,文件放在/www/100,内容显示this is 192.168.19.102.
建立一个192.168.19.103的网站 ,文件放在/www/200,内容显示this is 192.168.19.103.

配置网络

首先给虚拟机配置三块网卡并设置好IP地址,默认网卡已经配置好
[root@server_1 ~]# nmcli connection modify eno33554960 ipv4.addresses 192.168.19.102/24 ipv4.gateway 192.168.19.1 ipv4.dns 8.8.8.8 ipv4.method manual connection.autoconnect yes
[root@server_1 ~]# nmcli connection modify eno50332184 ipv4.addresses 192.168.19.103/24 ipv4.gateway 192.168.19.1 ipv4.dns 8.8.8.8 ipv4.method manual connection.autoconnect yes
[root@server_1 ~]# nmcli connection up eno33554960
[root@server_1 ~]# nmcli connection up eno50332184
也可以去图形界面配置IP地址,这里我的三块网卡IP地址分别为
192.168.19.101
192.168.19.102
192.168.19.103

编辑配置文件

[root@server_1 ~]# mkdir -p /www/{100,200}
[root@server_1 ~]# echo this is 192.168.19.102 > /www/100/index.html
[root@server_1 ~]# echo this is 192.168.19.103 > /www/200/index.html
[root@server_1 ~]# vim /etc/httpd/conf.d/vhost.conf

<Directory /www>
AllowOverride none
Require all granted
</Directory>

<VirtualHost 192.168.19.102>
DocumentRoot /www/100
ServerName 192.168.19.102
ServerAdmin root@localhost
</VirtualHost>

<VirtualHost 192.168.19.103>
DocumentRoot /www/200
ServerName 192.168.19.103
ServerAdmin root@localhost
</VirtualHost>

配置selinux

添加selinux上下文
[root@server_1 ~]# semanage fcontext -a -t httpd_sys_content_t /www"(/.*)?"
重新加载selinux上下文
[root@server_1 ~]# restorecon -vvFR /www
重启httpd服务
[root@server_1 ~]# systemctl restart httpd

客户端测试

[root@server_2 ~]# curl 192.168.19.102
this is 192.168.19.102
[root@server_2 ~]# curl 192.168.19.103
this is 192.168.19.103

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值