当前位置: 首页 > news >正文

02 Nginx虚拟主机

01 基于域名实现多任务

# 创建两个Nginx的conf文件
[root@likexy-nginx conf.d]# cat test01.conf 
server{listen 80;server_name www.test01.com;location / {root /code;index test01.html;}
}
[root@likexy-nginx conf.d]# cat test02.conf 
server{listen 80;server_name www.test02.com;location / {root /code;index test02.html;}
}
[root@likexy-nginx conf.d]# cd /code/
[root@likexy-nginx code]# cat test01.html 
test01
[root@likexy-nginx code]# cat test02.html 
test02
# 修改 C:\Windows\System32\drivers\etc\hosts
172.2.25.10	www.test01.com www.test02.com
image-20241124171430150
图1 在浏览器访问是test01
image-20241124171446623
图2 在浏览器访问是test02

02 Nginx基于多IP地址

02-1 多端口

[root@likexy-nginx conf.d]# cat test01.conf 
server{listen 80;server_name _;location / {root /code;index test01.html;}
}
[root@likexy-nginx conf.d]# cat test02.conf 
server{listen 81;server_name _;location / {root /code;index test02.html;}
}

image-20241124172122113

图3 在浏览器访问是test01

image-20241124172206745

图4 在浏览器访问是test02

02-2 多IP

# 添加网卡IP地址
[root@likexy-nginx conf.d]# nmcli c modify ens33 +ipv4.addresses 172.2.25.110/24[root@likexy-nginx conf.d]# nmcli c down ens33 && nmcli c up ens33 
成功停用连接 "ens33"(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/1)
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/2)

image-20241124172702227

图5 查看ens33网卡IP地址
# 两个Nginx的conf文件监听端口不一样
[root@likexy-nginx conf.d]# cat test01.conf 
server{listen 172.2.25.10:80;server_name _;location / {root /code;index test01.html;}
}
[root@likexy-nginx conf.d]# cat test02.conf 
server{listen 172.2.25.110:80;server_name _;location / {root /code;index test02.html;}
image-20241124173127449
图6 在浏览器访问是test01
image-20241124173320727
图7 在浏览器访问是test02

相关文章:

  • 如何畅通需求收集渠道,获取用户反馈?
  • 软考IPSEC案例分析
  • Linux进程信号(三)之信号产生2
  • 短剧小程序系统开发源码上架,短剧项目市场分析
  • 考研数学积分学
  • 渗透测试核心技术:内网渗透与横向移动
  • 类魔方 :多变组合,灵活复用
  • Estimation(估算):业务分析师的“不确定性对抗术”
  • Python黑魔法与底层原理揭秘:突破语言边界的深度探索
  • 【VMware】开启「共享文件夹」
  • 软件架构之-论软件系统架构评估以及应用
  • 批量下载AlphaFold结构
  • 2.1.2
  • LORA 微调 - LoRA 介绍与 LoRA 微调指南
  • vue3 elementplus tabs切换实现
  • 程序代码篇---python获取http界面上按钮或者数据输入
  • “二维前缀和”算法原理及模板
  • 亚马逊海卖助手有什么功能?海卖助手的主要功能与特点分析
  • mybatis中的resultMap的association及collectio的使用
  • Python训练营---Day29
  • 4年间职务侵占、受贿逾亿元,北京高院:严惩民企内部腐败
  • 三人在共享单车上印小广告被拘,北京警方专项打击非法小广告
  • 浙江广厦:诚挚道歉,涉事责任人交公安机关
  • 墨西哥海军帆船纽约撞桥事故已致2人死亡19人受伤
  • 李洋谈美国黑帮电影与黑帮文化
  • 15年全免费,内蒙古准格尔旗实现幼儿园到高中0学费