nginx反向代理和负载均衡配置

配置文件

位置 : /usr/local/software/nginx/conf

vim nginx.conf

在http大括号下配置:

upstream wnBalance{

server ip:端口 weight=比重 :1或者2; 1为配重高

server ip:端口 weight=1;

}

wnBalance : 代表括号中两个ip的变量名

位置 : /usr/local/software/nginx/conf/conf.d

配置default.conf

vim default.conf

location / {

#root /usr/share/nginx/html;

#index index.html index.htm;

proxy_pass http://wnBalance/api/nginx/hello;

}

wnBalance nginx.conf中upstream后面的文件名 后面跟上具体的接口

保存重启nginx后访问nginx的网站就会根据配重随机访问定义的服务器

相关推荐
Re_zero14 小时前
线上日志被清空?这段仅10行的 IO 代码里竟然藏着3个毒瘤
java·后端
洋洋技术笔记15 小时前
Spring Boot条件注解详解
java·spring boot
程序员清风1 天前
程序员兼职必看:靠谱软件外包平台挑选指南与避坑清单!
java·后端·面试
皮皮林5511 天前
利用闲置 Mac 从零部署 OpenClaw 教程 !
java
华仔啊2 天前
挖到了 1 个 Java 小特性:var,用完就回不去了
java·后端
SimonKing2 天前
SpringBoot整合秘笈:让Mybatis用上Calcite,实现统一SQL查询
java·后端·程序员
日月云棠2 天前
各版本JDK对比:JDK 25 特性详解
java
用户8307196840822 天前
Spring Boot 项目中日期处理的最佳实践
java·spring boot
JavaGuide2 天前
Claude Opus 4.6 真的用不起了!我换成了国产 M2.5,实测真香!!
java·spring·ai·claude code
IT探险家2 天前
Java 基本数据类型:8 种原始类型 + 数组 + 6 个新手必踩的坑
java