基于IP地址访问web服务器

基于IP访问web网站,当前网络的根目录为/www,创建当前网站虚拟目录,内容自定

第一步:配置网络,添加两个IP,192.168.198.10/24和192.168.198.11/24
[root@catyuan ~]# nmcli connection modify ens33 +ipv4.addresses 192.168.198.10/24 ipv4.gateway 192.168.198.1 ipv4.dns 114.114.114.114 ipv4.method manual connection.autoconnect yes
[root@catyuan ~]# nmcli connection modify ens33 +ipv4.addresses 192.168.198.11/24 ipv4.gateway 192.168.198.1 ipv4.dns 114.114.114.114 ipv4.method manual connection.autoconnect yes
[root@catyuan ~]# nmcli connection up ens33

第二步:创建网站存放目录,IP为192.168.198.10的文件存放在/www/10/,192.168.198.11的文件存放在/www/10下
[root@catyuan ~]# mkdir /www/{10,11} -pv
mkdir: created directory ‘/www’
mkdir: created directory ‘/www/10’
mkdir: created directory ‘/www/11’

第三步:编辑配置文件
[root@catyuan ~]# vim /etc/httpd/conf.d/vhosts.cof
<Directory "/www">
    AllowOverride None    ##允许覆盖
    # Allow open access: 
    Require all granted   ##设置目录访问权限
</Directory>

<VirtualHost 192.168.198.0:80>  IP地址
    DocumentRoot "/www/10"       ##指定当前主机访问网站
	ServerName 192.168.198.10     ##指定网站访问名称
    ErrorLog "/var/log/httpd/dummy-host.example.com-error_log"  ##错误日志
    CustomLog "/var/log/httpd/dummy-host.example.com-access_log" common  ##访问日志
</VirtualHost>

<VirtualHost 192.168.198.11:80>
    DocumentRoot "/www/11"
	ServerName 192.168.198.11
    ErrorLog "/var/log/httpd/dummy-host.example.com-error_log"
    CustomLog "/var/log/httpd/dummy-host.example.com-access_log" common
</VirtualHost>

第四步:网站内写入内容
[root@catyuan ~]# echo this is 192.168.198.10 > /www/10/index.html
[root@catyuan ~]# echo this is 192.168.198.11 > /www/11/index.html

第五步:重启服务并测试
[root@catyuan ~]# systemctl restart httpd

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值