[root@localhost ~]# systemctl stop firewalld 关防火墙
[root@localhost ~]# setenforce 0 关selinux
[root@localhost ~]# mount /dev/sr0 /mnt 挂载点
[root@localhost ~]# dnf install nginx -y 安装nginx
[root@localhost ~]# nmtui 当前主机添加多地址
[root@localhost ~]# ip a 检验
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:0c:29:0d:c3:06 brd ff:ff:ff:ff:ff:ff
altname enp3s0
inet 192.168.226.130/24 brd 192.168.226.255 scope global noprefixroute ens160
valid_lft forever preferred_lft forever
inet 192.168.226.139/24 brd 192.168.226.255 scope global secondary noprefixroute ens160
valid_lft forever preferred_lft forever
inet 192.168.226.140/24 brd 192.168.226.255 scope global secondary noprefixroute ens160
valid_lft forever preferred_lft forever
inet 192.168.226.129/24 brd 192.168.226.255 scope global secondary dynamic noprefixroute ens160
valid_lft 1787sec preferred_lft 1787sec
inet6 fe80::20c:29ff:fe0d:c306/64 scope link noprefixroute
[root@localhost ~]# nmcli connection up ens160
Connection successfully activated (D-Bus active path: /org/fre
[root@localhost ~]# vim /etc/nginx/conf.d/test_ip.conf 自定义nginx配置文件通过多地址区分多网站
[root@localhost ~]# cat /etc/nginx/conf.d/test_ip.conf
server {
listen 192.168.226.130:80;
root /www/ip/130;
location / {
}
}
server {
listen 192.168.226.139:80;
root /www/ip/139;
location / {
}
}
server {
listen 192.168.226.140:80;
root /www/ip/140;
location / {
}
}
[root@localhost ~]# mkdir /www/ip/{130,139,140} -pv 自定义nginx配置文件通过多地址区分多网站
mkdir: created directory '/www/ip'
mkdir: created directory '/www/ip/130'
mkdir: created directory '/www/ip/139'
mkdir: created directory '/www/ip/140'
[root@localhost ~]# echo this is 130 > /www/ip/130/index.html
[root@localhost ~]# echo this is 139 > /www/ip/139/index.html
[root@localhost ~]# echo this is 140 > /www/ip/140/index.html
[root@localhost ~]# systemctl restart nginx 重启服务加载配置
客户端连接测试