网站首页 > 博客文章 正文
nginx是一个高性能的HTTP和反向代理web服务器,通过它的反向代理功能,可以实现负载均衡
http服务负载均衡
例如有两个tomcat服务:127.0.0.1:8080/test,127.0.0.1:8081/test,需要做负载均衡,我们在它的http模块中,可以这样配置
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#配置做负载均衡的应用服务地址,注意名字 testserver 不要带下划线_,不然访问时会报错
upstream testserver{
server 127.0.0.1:8080;
server 127.0.0.1:8081;
}
server {
listen 80;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /test {
root html;
proxy_pass http://testserver/test;
proxy_redirect default;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
tcp服务负载均衡
例如有两个netty提供的tcp socket服务:127.0.0.1:8800,127.0.0.1:8801,需要做负载均衡,nginx监听8000端口,并对外提供服务,客户端连接8000端口,这样我们在它的stream模块中,可以这样配置
stream {
upstream nettyserver {
server 127.0.0.1:8800;
server 127.0.0.1:8801;
}
server {
listen 8000;
proxy_pass nettyserver;
}
}
好了,通过以上配置,就可以愉快使用nginx做负载均衡了,也来试试吧!
猜你喜欢
- 2024-12-19 nginx配置tcp代理
- 2024-12-19 Prometheus快速监控Nginx
- 2024-12-19 Nginx搭建RTMP推拉流服务器
- 2024-12-19 nginx入门——nginx访问日志(六)
- 2024-12-19 解决php因为输出内容太短无法流式(Stream)输出问题
- 2024-12-19 利用Nginx正向代理实现局域网电脑访问外网
- 2024-12-19 使用 Nginx 实现推流搭建自己的流媒体服务器
- 2024-12-19 Nginx模块开发:从源码剖析整个Nginx框架
- 2024-12-19 Linux下如何用nginx+ffmpeg搭建流媒体服务器
- 2024-12-19 Linux运维面试nginx都问哪些问题呢?
你 发表评论:
欢迎- 最近发表
-
- 给3D Slicer添加Python第三方插件库
- Python自动化——pytest常用插件详解
- Pycharm下安装MicroPython Tools插件(ESP32开发板)
- IntelliJ IDEA 2025.1.3 发布(idea 2020)
- IDEA+Continue插件+DeepSeek:开发者效率飙升的「三体组合」!
- Cursor:提升Python开发效率的必备IDE及插件安装指南
- 日本旅行时想借厕所、买香烟怎么办?便利商店里能解决大问题!
- 11天!日本史上最长黄金周来了!旅游万金句总结!
- 北川景子&DAIGO缘定1.11 召开记者会宣布结婚
- PIKO‘PPAP’ 洗脑歌登上美国告示牌
- 标签列表
-
- ifneq (61)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)