nginx超时转发机制
来源:互联网 发布:编程使用的安卓模拟器 编辑:程序博客网 时间:2024/05/20 18:01
nginx超时转发机制
配置
在配置nginx的时候,我们经常会配置upstream来配置后端转发的一些规则,最常见的就是nginx后面挂了几台tomcat的机器,upstream写法如下示例:
upstream linuxidc { server 192.168.31.114:8080; server 192.168.31.223:8080;}
下面是对应的server的配置
server { listen 80; server_name localhost; location / { proxy_pass http://linuxidc; proxy_connect_timeout 2s; proxy_read_timeout 2s; proxy_send_timeout 2s; }}
在nginx中,当一个请求到达后端机器,后端机器因某些原因(load高等等)响应变慢导致超时的时候,nginx会把这个请求转发到另外的后端机器上,这个配置是:
proxy_next_upstream on;
在nginx中是默认打开的。以下来做个试验:
后端192.168.31.114 192.168.31.223两台机器都是node的一个server,代码如下:
192.168.31.114:server.jsvar http = require("http"); http.createServer(function(request, response) { for(var i = 0; i < 1000000; i++) { console.log(i); } response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end(); }).listen(8080);192.168.31.223:server.jsvar http = require("http"); http.createServer(function(request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end(); }).listen(8080);
可以看到两者的区别在于114的机器在每次请求的时候会走一个循环,循环会导致读取超时;223的机器则是立刻返回响应。
验证
(1)112 223开启,nginx开启转发机制:
0 0
- nginx超时转发机制
- nginx 转发请求超时
- nginx超时转发请求问题
- nginx 超时机制
- nginx几种转发机制
- Nginx配置端口转发 映射 以及连接超时问题
- nginx 转发
- Nginx转发
- nginx转发
- nginx 转发
- Nginx转发
- nginx 超时
- Nginx转发代理配置
- nginx端口转发
- nginx转发规则
- Nginx 转发给 tomcat
- nginx转发apache
- nginx转发规则
- CentOS 7将linux服务加入系统启动 systemd service
- CUDA从组成到编程(二) Hello World!
- 安全快速更改MySQL数据库名称
- mysql数据库的备份与恢复
- 机器学习 特征工程 特征离散化
- nginx超时转发机制
- 数据库连接池
- VC++ 工程添加 Unicode Debug 和 Unicode Release编译支持
- hdu1092 - A+B for Input-Output Practice (IV)
- Fragment的相关用法第二篇
- ubuntu下Android Studio 提交代码至Github
- Android使用ADB启动应用程序
- MySql-5.7.17 -winx64的安装配置
- Linux Mint输入法配置