欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 文化 > 安装nginx实现多ip访问多网站

安装nginx实现多ip访问多网站

2024/10/25 11:06:29 来源:https://blog.csdn.net/wisdom_serein/article/details/143109736  浏览:    关键词:安装nginx实现多ip访问多网站

 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 identity

This 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
└── time

4 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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com