1,关闭防火墙,selinux
2,挂载,安装nginx
3,在主机的网卡添加多个ip地址(nmtui)
4,自定义nginx配置文件通过多个ip地址区分多网站
5,客户端连接测试
[root@localhost ~]# systemctl stop firewalld #关闭防火墙
[root@localhost ~]# setenforce 0 #关闭selinux
[root@localhost ~]# mount /dev/sr0 /mnt #挂载将dev sro设备挂载到/mnt目录下
mount: /mnt: /dev/sr0 already mounted on /run/media/redhat/RHEL-9-1-0-BaseOS-x86_64.
[root@localhost ~]# yum install nginx #安装nginx
Updating Subscription Management repositories.
Unable to read consumer identityThis system is not registered with an entitlement server. You can use subscription-manager to register.
Last metadata expiration check: 9:18:33 ago on Mon 21 Oct 2024 12:27:55 AM EDT.
Package nginx-1:1.20.1-13.el9.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@localhost ~]# ip a #添加ip地址
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: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
link/ether 00:0c:29:c3:1c:e9 brd ff:ff:ff:ff:ff:ff
altname enp3s0
inet 192.168.30.128/24 brd 192.168.30.255 scope global noprefixroute ens160
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fec3:1ce9/64 scope link tentative noprefixroute
valid_lft forever preferred_lft forever
3: ens224: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:c3:1c:f3 brd ff:ff:ff:ff:ff:ff
altname enp19s0
inet 192.168.108.129/24 brd 192.168.108.255 scope global noprefixroute ens224
valid_lft forever preferred_lft forever
inet 192.168.108.130/24 brd 192.168.108.255 scope global secondary noprefixroute ens224
valid_lft forever preferred_lft forever
inet 192.168.108.140/24 brd 192.168.108.255 scope global secondary noprefixroute ens224
valid_lft forever preferred_lft forever
inet 192.168.108.10/24 brd 192.168.108.255 scope global secondary noprefixroute ens224
valid_lft forever preferred_lft forever
inet6 fe80::2753:b90a:809c:f71e/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[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.108.130:80;
#server_name
root /test/130;
location / {
index index.html;
}
}
server {
listen 192.168.108.140:80;
#server_name
root /test/140;
location / {
index index.html;
}
}
[root@localhost ~]# mkdir /test/{130,140} -pv
mkdir: created directory '/test/130'
mkdir: created directory '/test/140'
[root@localhost ~]# tree /test
/test
├── 130
├── 140
├── a
├── a.hard
├── air
│ └── aaa
├── a.soft -> /test/a
└── time4 directories, 4 files
[root@localhost ~]# echo this is 130 > /test/130/index.html
[root@localhost ~]# echo this is 140 > /test/140/index.html
[root@localhost ~]# systemctl restart nginx
[root@localhost ~]# curl 192.168.108.130
this is 130