Linux上部署nginx实现多ip访问多网站

1,添加多个ip地址

使用nmtui命令或nmcli命令

nmtui方式:

nmcli方式:

root@localhost ip\]# nmcli conncetion ipv4.method manual ipv4.address 192.168.79.129/24 + 192.168.79.130/24 + 192.168.79.131 ipv4.gatway 192.68.79.2 ipv4.dns 114.114.114.114

激活网卡配置:

root@localhost ip\]# nmcli connection up ens160 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)

查看配置是否生效:

2,在/etc/nginx/conf.d/test_ip.conf 配置文件

server{

listen 192.168.79.129:80; -----监听IP地址,端口

root /ip/129;----访问目录文件

location / { ----访问本地/目录

index index.html;----索引文件名,默认 index.html

}

}

server{

listen 192.168.79.130:80;

root /ip/130;

location / {

index index.html;

}

}

server{

listen 192.168.79.131:80;

root /ip/131;

location / {

index index.html;

}

}

3,重启nginx服务

关闭相关服务

root@localhost \~\]# systemctl stop firewalld \[root@localhost \~\]# setenforce 0

重启配置

root@localhost /\]# systemctl restart nginx

4,创建相关目录文件

root@localhost /\]# mkdir /ip/{129,130,131} -pv mkdir: created directory '/ip' mkdir: created directory '/ip/129' mkdir: created directory '/ip/130' mkdir: created directory '/ip/131' \[root@localhost /\]# echo this is 129 \> /ip/129/index.html \[root@localhost /\]# echo this is 130 \> /ip/130/index.html \[root@localhost /\]# echo this is 131 \> /ip/131/index.html

5,访问网站

相关推荐
编织幻境的妖6 分钟前
Docker底层工作原理
运维·docker·容器
TDengine (老段)18 分钟前
TDengine IDMP 赋能新能源:光伏电站智能运维实践
大数据·运维·数据库·物联网·时序数据库·tdengine·涛思数据
小武~39 分钟前
#嵌入式Linux电源管理实战:深入解析CPU调频governor原理与优化
linux
gcfer40 分钟前
Docker 介绍和常用命令
运维·docker·容器
i***48612 小时前
Nginx中$http_host、$host、$proxy_host的区别
运维·nginx·http
Fɪʀᴇᴡᴏʀᴋs3 小时前
Oceanbase数据库—基于社区版本的数据库集群管理
运维·数据库·oceanbase
HalvmånEver3 小时前
Linux:基础开发工具(五)
linux·运维·服务器
qq_278984133 小时前
ubuntu vlan网络设置
linux·服务器·网络
q***58193 小时前
基础篇:Linux安装redis教程(详细)
linux·运维·redis
小二·3 小时前
Linux 高频面试题(50道 + 详细答案)
linux·运维·服务器