该模块为后端服务器提供简单的负载均衡(轮循调度和客户端 IP)。
示例:
upstream backend {
server backend1.example.com weight=5;
server backend2.example.com:8080;
server unix:/tmp/backend3;
}
server {
location / {
proxy_pass http://backend;
}
}
指令:
ip_hash
语法: ip_hash
默认值: 无
语境: upstream
This directive causes requests to be distributed between upstreams based on the IP-address of the client.
The key for the hash is the class-C network address of the client. This method guarantees that the client request will always be transferred to the same server. But if this server is considered inoperative, then the request of this client will be transferred
to another server. This gives a high probability clients will always connect to the same server.
It is not possible to combine ip_hash and weight methods for connection distribution. If one of the servers must be removed for some time, you must mark that server as *down*.
示例:
upstream backend {
ip_hash;
server backend1.example.com;
server backend2.example.com;
server backend3.example.com down;
server backend4.example.com;
}
server
语法: server name [parameters]
默认值: 无
语境: upstream
Directive assigns the name and the parameters of server. For the name it is possible to use a domain name, an address, port or unix socket. If domain name resolves to several addresses, then all are used.
weight = NUMBER - set weight of the server, if not set weight is equal to one.
max_fails = NUMBER - number of unsuccessful attempts at communicating with the server within the time period (assigned by parameter fail_timeout) after which it is considered inoperative. If not set, the number of attempts is one. A value of 0 turns off this
check. What is considered a failure is defined by proxy_next_upstream or fastcgi_next_upstream (except http_404 errors which do not count towards max_fails).
fail_timeout = TIME - the time during which must occur *max_fails* number of unsuccessful attempts at communication with the server that would cause the server to be considered inoperative, and also the time for which the server will be considered inoperative
(before another attempt is made). If not set the time is 10 seconds. fail_timeout has nothing to do with upstream response time, use proxy_connect_timeout and proxy_read_timeout for controlling this.
down - marks server as permanently offline, to be used with the directive ip_hash.
backup - (0.6.7 or later) only uses this server if the non-backup servers are all down or busy
示例:
upstream backend {
server backend1.example.com weight=5;
server 127.0.0.1:8080 max_fails=3 fail_timeout=30s;
server unix:/tmp/backend3;
}
upstream
语法: upstream name { ... }
默认值: 无
语境: http
这个指令描述了一个服务器的集合,该集合可被用于 proxy_pass 和 fastcgi_pass 指令中,作为一个单独的实体。
这些服务器可以是监听在不同的端口,另外,并发使用同时监听 TCP 端口和 Unix 套接字的服务器是可能的。
这些服务器能被分配不同的权重。如果没有指定,则都为一。
示例:
upstream backend {
server backend1.example.com weight=5;
server 127.0.0.1:8080 max_fails=3 fail_timeout=30s;
server unix:/tmp/backend3;
}
Requests are distributed according to the servers in round-robin manner with respect of the server weight.
For example of every 7 seven requests given above they will be distributed like this: 5 requests on backend1.example.com and one request to the second and the third of server. If with an attempt at the work with the server error occurred, then the request will
be transmitted to the following server and then until all workers of server not are tested. If successful answer is not succeeded in obtaining from all servers, then to client will be returned the result of work with the last server.
变量:
自版本 0.5.18 之后,可通过 log_module 模块将变量值写入日志。
示例:
log_format timing '$remote_addr - $remote_user [$time_local] $request '
'upstream_response_time $upstream_response_time '
'msec $msec request_time $request_time';
log_format up_head '$remote_addr - $remote_user [$time_local] $request '
'upstream_http_content_type $upstream_http_content_type';
$upstream_addr
Address of the upstream server that handled the request
$upstream_cache_status
Appeared in 0.8.3. Possible values:
MISS
EXPIRED - expired, request was passed to backend
UPDATING - expired, stale response was used due to proxy/fastcgi_cache_use_stale updating
STALE - expired, stale response was used due to proxy/fastcgi_cache_use_stale
HIT
$upstream_status
Upstream server status of the answer
$upstream_response_time
Response time in milliseconds. Several answers are divided by commas and colons.
$upstream_http_$HEADER
Arbitrary HTTP protocol headers, for example:
$upstream_http_host
原始俄文文档:http://sysoev.ru/nginx/docs/http/ngx_http_upstream.html
原始英文wiki文档:http://wiki.nginx.org/NginxHttpUpstreamModule
分享到:
相关推荐
nginx的内部结构是由核心部分和一系列的功能模块所组成。这样划分是为了使得每个模块的功能相对简单,便于开发,同时也...这样的模块化设计类似于面向对象中的接口类,它增强了nginx源码的可读性、可扩充性和可维护性。
Nginx的主配置文件为“/etc/nginx/nginx.conf”,我们输入“vim /etc/nginx/nginx.conf”来查看配置文件的详细信息。 修改访问权限 在Nginx的主配置文件中的http,service或者location标签中,写入配置信息,如:...
两本书,带完整详细目录: Nginx高性能Web服务器详解 深入理解Nginx:模块开发与架构解析(第2版)陶辉著
在kali中输入“nginx -t”来查看配置文件信息。 2.打开主配置文件“/etc/nginx/nginx.conf” 3.刚安装的nginx,配置文件里可能信息不齐导致无法启动服务,我们需要手动在http{}标签内输入以下代码: 有这部分代码,...
也是IMAP/POP3/SMTP代理服务器,是由俄罗斯人lgor Sysoev开发,支持模块加载和卸载,其中upload_module和upload_progress_module就是第三方开发的模块,并没有加入到Nginx的源码中,upload_module是上传文件到服务器...
conf/nginx.conf 为配置文件实例 RTMP监听 1935 端口,启用live 和hls 两个application HTTP监听 8080 端口, * :8080/stat 查看stream状态 * :8080/index.html 为一个直播播放与直播发布测试器 * :8080/vod....
造成nginx目录列出的原因是主配置文件nginx.coonf中的一句代码”autoindex on”。 Nginx禁止目录列出配置 ”autoindex on”的意思是允许显示列表功能,想要禁止显示列表功能的话只需要将”autoindex on”改为”...
nginx配置nginScript模块 当前的版本是一个preview版本,nginx可以通过两种方式执行JS代码: 可以在nginx的配置中计算一些值 在nginx生成content的时候执行 nginx源码安装nginScript模块如下: 一、下载安装 最新...
k8s-修改ingress-nginx-controller中nginx配置文件参数参考
Web应用安全:Nginx禁止目录列出配置实验.doc
Nginx权限配置 Nginx权限配置 1、Nginx简介 Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力在同...
nginx命令参数用法详细介绍 nginx命令:启动nginx 在Windows上安装好nginx后,我们需要启动nginx服务,启动nginx服务的命令行操作主要有两种方式,即 C:/nginx-0.8.53>nginx.exe 或者 C:/nginx-0.8.53>start ...
test-nginx, 面向 Nginx C 模块和 OpenResty Lua库开发的数据驱动测试 电子邮件名称Test::Nginx - Nginx MODULE 和 Nginx/openresty库和应用程序的数据驱动测试脚手架 table-内容NAME描述用户指南使用 Test::Nginx ...
开源电子书:Nginx 开发手册文档.pdf
Web应用安全:Nginx日志配置.pptx
Web应用安全:Nginx禁止目录列出配置文本.docx
Web应用安全:Nginx日志配置文本.docx
2.作为代理服务器,Nginx可以实现无缓存的反向代理加速,提高网站运行速度 3.作为负载均衡服务器,Nginx既可以在内部直接支持Rails和PHP,也可以支
nginx for windows nginx-1.14.0.rar 第一步: nginx-1.14.0.rar右键解压文件到D盘(不支持中文目录) D:\nginx-1.14.0\nginx.exe 第二步: 拷贝证书到目录cert 第三步: conf/vhosts.conf 修改网站配置文件 server { ....
tomcat 第⼀部分:Tomcat 系统架构与...第⼆部分:Nginx核⼼配置⽂件解读 第三部分:Nginx应⽤场景之反向代理 第四部分:Nginx应⽤场景之负载均衡 第五部分:Nginx应⽤场景之动静分离 第六部分:Nginx底层进程机制剖析