基于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