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,访问网站

相关推荐
释怀不想释怀2 分钟前
Linux(复习常见命令)
linux·运维·服务器
Wpa.wk2 分钟前
接口自动化 - 解决大量响应数据字段的格式断言 -Json-schema
运维·经验分享·测试工具·自动化·json·接口测试
_F_y5 分钟前
负载均衡在线oj(文件版)
linux·运维·负载均衡
Chase_______9 分钟前
【Linux指南】:vi编辑器
linux·运维·编辑器
2501_9167665411 分钟前
Springboot+vue前后端分离项目部署到云服务器
服务器
Dxy123931021616 分钟前
Nginx中的worker_processes如何设置:从“盲目填数”到“精准调优”
运维·nginx
礼拜天没时间.17 分钟前
【生产级实战】Linux 集群时间同步详解(NTP + Cron,超详细)
linux·运维·服务器·时间同步·cron·ntp
艾莉丝努力练剑17 分钟前
【Linux进程控制(一)】进程创建是呼吸,进程终止是死亡,进程等待是重生:进程控制三部曲
android·java·linux·运维·服务器·人工智能·安全
NEAI_N17 分钟前
嵌入式 Linux 中 system() 返回值的正确判定
linux·运维·服务器
瀚高PG实验室19 分钟前
无法连接到服务器:连接被拒绝
运维·服务器·瀚高数据库