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的网站就会根据配重随机访问定义的服务器

相关推荐
豆沙沙包?14 分钟前
2026年--Lc329-735. 小行星碰撞(栈)--java版
java·开发语言
爆更小哇32 分钟前
Selenium自动化测试函数全解析(二)
java·selenium·测试工具·自动化
C雨后彩虹32 分钟前
计算误码率
java·数据结构·算法·华为·面试
fanruitian36 分钟前
Springboot项目父子工程
java·数据库·spring boot
小肖爱笑不爱笑41 分钟前
SpringBoot Web
java·http协议·分层解耦·web后端
柒.梧.43 分钟前
Spring核心知识全解析:从入门实战到进阶
java·后端·spring
乌日尼乐1 小时前
【Java基础整理】Java字符串处理,String、StringBuffer、StringBuilder
java·后端
全栈独立开发者1 小时前
点餐系统装上了“DeepSeek大脑”:基于 Spring AI + PgVector 的 RAG 落地指南
java·人工智能·spring
dmonstererer1 小时前
【k8s设置污点/容忍】
java·容器·kubernetes
super_lzb1 小时前
mybatis拦截器ParameterHandler详解
java·数据库·spring boot·spring·mybatis