{"id":18,"date":"2023-03-13T13:35:35","date_gmt":"2023-03-13T06:35:35","guid":{"rendered":"http:\/\/kul.my.id\/w\/?p=18"},"modified":"2023-03-15T02:15:17","modified_gmt":"2023-03-14T19:15:17","slug":"http-load-balancing","status":"publish","type":"post","link":"http:\/\/kul.my.id\/w\/2023\/03\/http-load-balancing\/","title":{"rendered":"KUL Load Balancing"},"content":{"rendered":"<p>Load balance HTTP traffic across web or application server groups, with several algorithms and advanced features like slow-start and session persistence.<\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"overview\">Overview<\/h2>\n<p>Load balancing across multiple application instances is a commonly used technique for optimizing resource utilization, maximizing throughput, reducing latency, and ensuring fault\u2011tolerant configurations.<\/p>\n<p>Watch the\u00a0<a href=\"https:\/\/www.nginx.com\/resources\/webinars\/nginx-plus-for-load-balancing-30-min\/\" target=\"_blank\" rel=\"noopener\">NGINX Plus for Load Balancing and Scaling<\/a>\u00a0webinar on demand for a deep dive on techniques that NGINX users employ to build large\u2011scale, highly available web services.<\/p>\n<p>NGINX and NGINX Plus can be used in different deployment scenarios as a\u00a0<a href=\"https:\/\/www.nginx.com\/blog\/nginx-load-balance-deployment-models\/\" target=\"_blank\" rel=\"noopener\">very efficient HTTP load balancer<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"proxying-http-traffic-to-a-group-of-servers\">Proxying HTTP Traffic to a Group of Servers<\/h2>\n<p>To start using NGINX Plus or NGINX Open Source to load balance HTTP traffic to a group of servers, first you need to define the group with the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#upstream\" target=\"_blank\" rel=\"noopener\"><code>upstream<\/code><\/a>\u00a0directive. The directive is placed in the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_core_module.html#http\" target=\"_blank\" rel=\"noopener\"><code>http<\/code><\/a>\u00a0context.<\/p>\n<p>Servers in the group are configured using the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#server\" target=\"_blank\" rel=\"noopener\"><code>server<\/code><\/a>\u00a0directive (not to be confused with the\u00a0<code>server<\/code>\u00a0block that defines a virtual server running on NGINX). For example, the following configuration defines a group named\u00a0<strong>backend<\/strong>\u00a0and consists of three server configurations (which may resolve in more than three actual servers):<\/p>\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">http<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">upstream<\/span> <span class=\"s\">backend<\/span> <span class=\"p\">{<\/span>\r\n        <span class=\"kn\">server<\/span> <span class=\"s\">backend1.example.com<\/span> <span class=\"s\">weight=5<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"kn\">server<\/span> <span class=\"s\">backend2.example.com<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"kn\">server<\/span> <span class=\"mi\">192<\/span><span class=\"s\">.0.0.1<\/span> <span class=\"s\">backup<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"p\">}<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<p>To pass requests to a server group, the name of the group is specified in the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_proxy_module.html#proxy_pass\" target=\"_blank\" rel=\"noopener\"><code>proxy_pass<\/code><\/a>\u00a0directive (or the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_fastcgi_module.html#fastcgi_pass\" target=\"_blank\" rel=\"noopener\"><code>fastcgi_pass<\/code><\/a>,\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_memcached_module.html#memcached_pass\" target=\"_blank\" rel=\"noopener\"><code>memcached_pass<\/code><\/a>,\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_scgi_module.html#scgi_pass\" target=\"_blank\" rel=\"noopener\"><code>scgi_pass<\/code><\/a>, or\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_uwsgi_module.html#uwsgi_pass\" target=\"_blank\" rel=\"noopener\"><code>uwsgi_pass<\/code><\/a>\u00a0directives for those protocols.) In the next example, a virtual server running on NGINX passes all requests to the\u00a0<strong>backend<\/strong>\u00a0upstream group defined in the previous example:<\/p>\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">server<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">location<\/span> <span class=\"s\">\/<\/span> <span class=\"p\">{<\/span>\r\n        <span class=\"kn\">proxy_pass<\/span> <span class=\"s\">http:\/\/backend<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"p\">}<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<p>The following example combines the two snippets above and shows how to proxy HTTP requests to the\u00a0<strong>backend<\/strong>\u00a0server group. The group consists of three servers, two of them running instances of the same application while the third is a backup server. Because no load\u2011balancing algorithm is specified in the\u00a0<code>upstream<\/code>\u00a0block, NGINX uses the default algorithm, Round Robin:<\/p>\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">http<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">upstream<\/span> <span class=\"s\">backend<\/span> <span class=\"p\">{<\/span>\r\n        <span class=\"kn\">server<\/span> <span class=\"s\">backend1.example.com<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"kn\">server<\/span> <span class=\"s\">backend2.example.com<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"kn\">server<\/span> <span class=\"mi\">192<\/span><span class=\"s\">.0.0.1<\/span> <span class=\"s\">backup<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"p\">}<\/span>\r\n    \r\n    <span class=\"kn\">server<\/span> <span class=\"p\">{<\/span>\r\n        <span class=\"kn\">location<\/span> <span class=\"s\">\/<\/span> <span class=\"p\">{<\/span>\r\n            <span class=\"kn\">proxy_pass<\/span> <span class=\"s\">http:\/\/backend<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"p\">}<\/span>\r\n    <span class=\"p\">}<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<h2 id=\"choosing-a-load-balancing-method\">Choosing a Load-Balancing Method<\/h2>\n<p>NGINX Open Source supports four load\u2011balancing methods, and NGINX Plus adds two more methods:<\/p>\n<ol>\n<li>Round Robin \u2013 Requests are distributed evenly across the servers, with\u00a0<a href=\"https:\/\/docs.nginx.com\/nginx\/admin-guide\/load-balancer\/http-load-balancer\/#weights\">server weights<\/a>\u00a0taken into consideration. This method is used by default (there is no directive for enabling it):\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">upstream<\/span> <span class=\"s\">backend<\/span> <span class=\"p\">{<\/span>\r\n   <span class=\"c1\"># no load balancing method is specified for Round Robin\r\n<\/span>   <span class=\"kn\">server<\/span> <span class=\"s\">backend1.example.com<\/span><span class=\"p\">;<\/span>\r\n   <span class=\"kn\">server<\/span> <span class=\"s\">backend2.example.com<\/span><span class=\"p\">;<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<\/li>\n<li><a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#least_conn\" target=\"_blank\" rel=\"noopener\">Least Connections<\/a>\u00a0\u2013 A request is sent to the server with the least number of active connections, again with\u00a0<a href=\"https:\/\/docs.nginx.com\/nginx\/admin-guide\/load-balancer\/http-load-balancer\/#weights\">server weights<\/a>\u00a0taken into consideration:\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">upstream<\/span> <span class=\"s\">backend<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">least_conn<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend1.example.com<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend2.example.com<\/span><span class=\"p\">;<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<\/li>\n<li><a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#ip_hash\" target=\"_blank\" rel=\"noopener\">IP Hash<\/a>\u00a0\u2013 The server to which a request is sent is determined from the client IP address. In this case, either the first three octets of the IPv4\u00a0address or the whole IPv6\u00a0address are used to calculate the hash value. The method guarantees that requests from the same address get to the same server unless it is not available.\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">upstream<\/span> <span class=\"s\">backend<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">ip_hash<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend1.example.com<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend2.example.com<\/span><span class=\"p\">;<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<p>If one of the servers needs to be temporarily removed from the load\u2011balancing rotation, it can be marked with the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#down\" target=\"_blank\" rel=\"noopener\">down<\/a>\u00a0parameter in order to preserve the current hashing of client IP addresses. Requests that were to be processed by this server are automatically sent to the next server in the group:<\/p>\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">upstream<\/span> <span class=\"s\">backend<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend1.example.com<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend2.example.com<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend3.example.com<\/span> <span class=\"s\">down<\/span><span class=\"p\">;<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<\/li>\n<li>Generic\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#hash\" target=\"_blank\" rel=\"noopener\">Hash<\/a>\u00a0\u2013 The server to which a request is sent is determined from a user\u2011defined key which can be a text string, variable, or a combination. For example, the key may be a paired source IP address and port, or a URI as in this example:\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">upstream<\/span> <span class=\"s\">backend<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">hash<\/span> <span class=\"nv\">$request_uri<\/span> <span class=\"s\">consistent<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend1.example.com<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend2.example.com<\/span><span class=\"p\">;<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<p>The optional\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#hash\" target=\"_blank\" rel=\"noopener\">consistent<\/a>\u00a0parameter to the\u00a0<code>hash<\/code>\u00a0directive enables\u00a0<a href=\"http:\/\/www.last.fm\/user\/RJ\/journal\/2007\/04\/10\/rz_libketama_-_a_consistent_hashing_algo_for_memcache_clients\" target=\"_blank\" rel=\"noopener\">ketama<\/a>\u00a0consistent\u2011hash load balancing. Requests are evenly distributed across all upstream servers based on the user\u2011defined hashed key value. If an upstream server is added to or removed from an upstream group, only a few keys are remapped which minimizes cache misses in the case of load\u2011balancing cache servers or other applications that accumulate state.<\/li>\n<li><a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#least_time\" target=\"_blank\" rel=\"noopener\">Least Time<\/a>\u00a0(NGINX Plus only)\u00a0\u2013 For each request, NGINX Plus selects the server with the lowest average latency and the lowest number of active connections, where the lowest average latency is calculated based on which of the following\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#least_time\" target=\"_blank\" rel=\"noopener\">parameters<\/a>\u00a0to the\u00a0<code>least_time<\/code>\u00a0directive is included:\n<ul>\n<li><code>header<\/code>\u00a0\u2013 Time to receive the first byte from the server<\/li>\n<li><code>last_byte<\/code>\u00a0\u2013 Time to receive the full response from the server<\/li>\n<li><code>last_byte inflight<\/code>\u00a0\u2013 Time to receive the full response from the server, taking into account incomplete requests<\/li>\n<\/ul>\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">upstream<\/span> <span class=\"s\">backend<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">least_time<\/span> <span class=\"s\">header<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend1.example.com<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend2.example.com<\/span><span class=\"p\">;<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<\/li>\n<li><a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#random\" target=\"_blank\" rel=\"noopener\">Random<\/a>\u00a0\u2013 Each request will be passed to a randomly selected server. If the\u00a0<code>two<\/code>\u00a0parameter is specified, first, NGINX randomly selects two servers taking into account server weights, and then chooses one of these servers using the specified method:\n<ul>\n<li><code>least_conn<\/code>\u00a0\u2013 The least number of active connections<\/li>\n<li><code>least_time=header<\/code>\u00a0(NGINX Plus) \u2013 The least average time to receive the response header from the server (<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#var_upstream_header_time\" target=\"_blank\" rel=\"noopener\"><code>$upstream_header_time<\/code><\/a>)<\/li>\n<li><code>least_time=last_byte<\/code>\u00a0(NGINX Plus) \u2013 The least average time to receive the full response from the server (<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#var_upstream_response_time\" target=\"_blank\" rel=\"noopener\"><code>$upstream_response_time<\/code><\/a>)<\/li>\n<\/ul>\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">upstream<\/span> <span class=\"s\">backend<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">random<\/span> <span class=\"s\">two<\/span> <span class=\"s\">least_time=last_byte<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend1.example.com<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend2.example.com<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend3.example.com<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend4.example.com<\/span><span class=\"p\">;<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<p>The\u00a0<strong>Random<\/strong>\u00a0load balancing method should be used for distributed environments where multiple load balancers are passing requests to the same set of backends. For environments where the load balancer has a full view of all requests, use other load balancing methods, such as round robin, least connections and least time.<\/li>\n<\/ol>\n<blockquote><p><strong>Note:<\/strong>\u00a0When configuring any method other than Round Robin, put the corresponding directive (<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#hash\" target=\"_blank\" rel=\"noopener\"><code>hash<\/code><\/a>,\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#ip_hash\" target=\"_blank\" rel=\"noopener\"><code>ip_hash<\/code><\/a>,\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#least_conn\" target=\"_blank\" rel=\"noopener\"><code>least_conn<\/code><\/a>,\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#least_time\" target=\"_blank\" rel=\"noopener\"><code>least_time<\/code><\/a>, or\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#random\" target=\"_blank\" rel=\"noopener\"><code>random<\/code><\/a>) above the list of\u00a0<code>server<\/code>\u00a0directives in the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#upstream\" target=\"_blank\" rel=\"noopener\"><code>upstream {}<\/code><\/a>\u00a0block.<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<h2 id=\"server-weights\">Server Weights<\/h2>\n<p>By default, NGINX distributes requests among the servers in the group according to their weights using the Round\u00a0Robin method. The\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#weight\" target=\"_blank\" rel=\"noopener\"><code>weight<\/code><\/a>\u00a0parameter to the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#server\" target=\"_blank\" rel=\"noopener\"><code>server<\/code><\/a>\u00a0directive sets the weight of a server; the default is\u00a0<code>1<\/code>:<\/p>\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">upstream<\/span> <span class=\"s\">backend<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend1.example.com<\/span> <span class=\"s\">weight=5<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend2.example.com<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"mi\">192<\/span><span class=\"s\">.0.0.1<\/span> <span class=\"s\">backup<\/span><span class=\"p\">;<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<p>In the example,\u00a0<strong>backend1.example.com<\/strong>\u00a0has weight\u00a0<code>5<\/code>; the other two servers have the default weight (<code>1<\/code>), but the one with IP address\u00a0<code>192.0.0.1<\/code>\u00a0is marked as a\u00a0<code>backup<\/code>\u00a0server and does not receive requests unless both of the other servers are unavailable. With this configuration of weights, out of every\u00a0<code>6<\/code>\u00a0requests,\u00a0<code>5<\/code>\u00a0are sent to\u00a0<strong>backend1.example.com<\/strong>\u00a0and\u00a0<code>1<\/code>\u00a0to\u00a0<strong>backend2.example.com<\/strong>.<\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"server-slow-start\">Server Slow-Start<\/h2>\n<p>The server slow\u2011start feature prevents a recently recovered server from being overwhelmed by connections, which may time out and cause the server to be marked as failed again.<\/p>\n<p>In NGINX Plus, slow\u2011start allows an upstream server to gradually recover its weight from\u00a0<code>0<\/code>\u00a0to its nominal value after it has been recovered or became available. This can be done with the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#slow_start\" target=\"_blank\" rel=\"noopener\"><code>slow_start<\/code><\/a>\u00a0parameter to the\u00a0<code>server<\/code>\u00a0directive:<\/p>\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">upstream<\/span> <span class=\"s\">backend<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend1.example.com<\/span> <span class=\"s\">slow_start=30s<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend2.example.com<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"mi\">192<\/span><span class=\"s\">.0.0.1<\/span> <span class=\"s\">backup<\/span><span class=\"p\">;<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<p>The time value (here,\u00a0<code>30<\/code>\u00a0seconds) sets the time during which NGINX Plus ramps up the number of connections to the server to the full value.<\/p>\n<p>Note that if there is only a single server in a group, the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#max_fails\" target=\"_blank\" rel=\"noopener\"><code>max_fails<\/code><\/a>,\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#fail_timeout\" target=\"_blank\" rel=\"noopener\"><code>fail_timeout<\/code><\/a>, and\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#slow_start\" target=\"_blank\" rel=\"noopener\"><code>slow_start<\/code><\/a>\u00a0parameters to the\u00a0<code>server<\/code>\u00a0directive are ignored and the server is never considered unavailable.<\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"enabling-session-persistence\">Enabling Session Persistence<\/h2>\n<p>Session persistence means that NGINX Plus identifies user sessions and routes all requests in a given session to the same upstream server.<\/p>\n<p>NGINX Plus supports three session persistence methods. The methods are set with the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#sticky\" target=\"_blank\" rel=\"noopener\"><code>sticky<\/code><\/a>\u00a0directive. (For session persistence with NGINX Open Source, use the\u00a0<code>hash<\/code>\u00a0or\u00a0<code>ip_hash<\/code>\u00a0directive as described\u00a0<a href=\"https:\/\/docs.nginx.com\/nginx\/admin-guide\/load-balancer\/http-load-balancer\/#method\">above<\/a>.)<\/p>\n<ul>\n<li><a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#sticky_cookie\" target=\"_blank\" rel=\"noopener\">Sticky cookie<\/a>\u00a0\u2013 NGINX Plus adds a session cookie to the first response from the upstream group and identifies the server that sent the response. The client\u2019s next request contains the cookie value and NGINX Plus route the request to the upstream server that responded to the first request:\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">upstream<\/span> <span class=\"s\">backend<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend1.example.com<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend2.example.com<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">sticky<\/span> <span class=\"s\">cookie<\/span> <span class=\"s\">srv_id<\/span> <span class=\"s\">expires=1h<\/span> <span class=\"s\">domain=.example.com<\/span> <span class=\"s\">path=\/<\/span><span class=\"p\">;<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<p>In the example, the\u00a0<code>srv_id<\/code>\u00a0parameter sets the name of the cookie. The optional\u00a0<code>expires<\/code>\u00a0parameter sets the time for the browser to keep the cookie (here,\u00a0<code>1<\/code>\u00a0hour). The optional\u00a0<code>domain<\/code>\u00a0parameter defines the domain for which the cookie is set, and the optional\u00a0<code>path<\/code>\u00a0parameter defines the path for which the cookie is set. This is the simplest session persistence method.<\/li>\n<li><a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#sticky_route\" target=\"_blank\" rel=\"noopener\">Sticky route<\/a>\u00a0\u2013 NGINX Plus assigns a \u201croute\u201d to the client when it receives the first request. All subsequent requests are compared to the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#route\" target=\"_blank\" rel=\"noopener\"><code>route<\/code><\/a>\u00a0parameter of the\u00a0<code>server<\/code>\u00a0directive to identify the server to which the request is proxied. The route information is taken from either a cookie or the request URI.\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">upstream<\/span> <span class=\"s\">backend<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend1.example.com<\/span> <span class=\"s\">route=a<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend2.example.com<\/span> <span class=\"s\">route=b<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">sticky<\/span> <span class=\"s\">route<\/span> <span class=\"nv\">$route_cookie<\/span> <span class=\"nv\">$route_uri<\/span><span class=\"p\">;<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<\/li>\n<li><a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#sticky_learn\" target=\"_blank\" rel=\"noopener\">Sticky learn<\/a>\u00a0method \u2013 NGINX Plus first finds session identifiers by inspecting requests and responses. Then NGINX Plus \u201clearns\u201d which upstream server corresponds to which session identifier. Generally, these identifiers are passed in a HTTP cookie. If a request contains a session identifier already \u201clearned\u201d, NGINX Plus forwards the request to the corresponding server:\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">upstream<\/span> <span class=\"s\">backend<\/span> <span class=\"p\">{<\/span>\r\n   <span class=\"kn\">server<\/span> <span class=\"s\">backend1.example.com<\/span><span class=\"p\">;<\/span>\r\n   <span class=\"kn\">server<\/span> <span class=\"s\">backend2.example.com<\/span><span class=\"p\">;<\/span>\r\n   <span class=\"kn\">sticky<\/span> <span class=\"s\">learn<\/span>\r\n       <span class=\"s\">create=<\/span><span class=\"nv\">$upstream_cookie_examplecookie<\/span>\r\n       <span class=\"s\">lookup=<\/span><span class=\"nv\">$cookie_examplecookie<\/span>\r\n       <span class=\"s\">zone=client_sessions:1m<\/span>\r\n       <span class=\"s\">timeout=1h<\/span><span class=\"p\">;<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<p>In the example, one of the upstream servers creates a session by setting the cookie\u00a0<code>EXAMPLECOOKIE<\/code>\u00a0in the response.<\/p>\n<p>The mandatory\u00a0<code>create<\/code>\u00a0parameter specifies a variable that indicates how a new session is created. In the example, new sessions are created from the cookie\u00a0<code>EXAMPLECOOKIE<\/code>\u00a0sent by the upstream server.<\/p>\n<p>The mandatory\u00a0<code>lookup<\/code>\u00a0parameter specifies how to search for existing sessions. In our example, existing sessions are searched in the cookie\u00a0<code>EXAMPLECOOKIE<\/code>\u00a0sent by the client.<\/p>\n<p>The mandatory\u00a0<code>zone<\/code>\u00a0parameter specifies a shared memory zone where all information about sticky sessions is kept. In our example, the zone is named\u00a0<strong>client_sessions<\/strong>\u00a0and is\u00a0<code>1<\/code>\u00a0megabyte in size.<\/p>\n<p>This is a more sophisticated session persistence method than the previous two as it does not require keeping any cookies on the client side: all info is kept server\u2011side in the shared memory zone.<\/p>\n<p>If there are several NGINX instances in a cluster that use the \u201csticky learn\u201d method, it is possible to sync the contents of their shared memory zones on conditions that:<\/p>\n<ul>\n<li>the zones have the same name<\/li>\n<li>the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/stream\/ngx_stream_zone_sync_module.html#zone_sync\" target=\"_blank\" rel=\"noopener\"><code>zone_sync<\/code><\/a>\u00a0functionality is configured on each instance<\/li>\n<li>the\u00a0<code>sync<\/code>\u00a0parameter is specified<\/li>\n<\/ul>\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\">   <span class=\"k\">sticky<\/span> <span class=\"s\">learn<\/span>\r\n       <span class=\"s\">create=<\/span><span class=\"nv\">$upstream_cookie_examplecookie<\/span>\r\n       <span class=\"s\">lookup=<\/span><span class=\"nv\">$cookie_examplecookie<\/span>\r\n       <span class=\"s\">zone=client_sessions:1m<\/span>\r\n       <span class=\"s\">timeout=1h<\/span>\r\n       <span class=\"s\">sync<\/span><span class=\"p\">;<\/span>\r\n<span class=\"k\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<p>See\u00a0<a href=\"https:\/\/docs.nginx.com\/nginx\/admin-guide\/high-availability\/zone_sync\/\">Runtime State Sharing in a Cluster<\/a>\u00a0for details.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2 id=\"limiting-the-number-of-connections\">Limiting the Number of Connections<\/h2>\n<p>With NGINX Plus, it is possible to limit the number of active connections to an upstream server by specifying the maximum number with the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#max_conns\" target=\"_blank\" rel=\"noopener\"><code>max_conns<\/code><\/a>\u00a0parameter.<\/p>\n<p>If the\u00a0<code>max_conns<\/code>\u00a0limit has been reached, the request is placed in a queue for further processing, provided that the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#queue\" target=\"_blank\" rel=\"noopener\"><code>queue<\/code><\/a>\u00a0directive is also included to set the maximum number of requests that can be simultaneously in the queue:<\/p>\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">upstream<\/span> <span class=\"s\">backend<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend1.example.com<\/span> <span class=\"s\">max_conns=3<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"s\">backend2.example.com<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">queue<\/span> <span class=\"mi\">100<\/span> <span class=\"s\">timeout=70<\/span><span class=\"p\">;<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<p>If the queue is filled up with requests or the upstream server cannot be selected during the timeout specified by the optional\u00a0<code>timeout<\/code>\u00a0parameter, the client receives an error.<\/p>\n<p>Note that the\u00a0<code>max_conns<\/code>\u00a0limit is ignored if there are idle\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#keepalive\" target=\"_blank\" rel=\"noopener\"><code>keepalive<\/code><\/a>\u00a0connections opened in other\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/ngx_core_module.html#worker_processes\" target=\"_blank\" rel=\"noopener\"><code>worker processes<\/code><\/a>. As a result, the total number of connections to the server might exceed the\u00a0<code>max_conns<\/code>\u00a0value in a configuration where the memory is\u00a0<a href=\"https:\/\/docs.nginx.com\/nginx\/admin-guide\/load-balancer\/http-load-balancer\/#zone\">shared with multiple worker processes<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"configuring-health-checks\">Configuring Health Checks<\/h2>\n<p>NGINX can continually test your HTTP upstream servers, avoid the servers that have failed, and gracefully add the recovered servers into the load\u2011balanced group.<\/p>\n<p>See\u00a0<a href=\"https:\/\/docs.nginx.com\/nginx\/admin-guide\/load-balancer\/http-health-check\/\">HTTP Health Checks<\/a>\u00a0for instructions how to configure health checks for HTTP.<\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"sharing-data-with-multiple-worker-processes\">Sharing Data with Multiple Worker Processes<\/h2>\n<p>If an\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#upstream\" target=\"_blank\" rel=\"noopener\"><code>upstream<\/code><\/a>\u00a0block does not include the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#zone\" target=\"_blank\" rel=\"noopener\"><code>zone<\/code><\/a>\u00a0directive, each worker process keeps its own copy of the server group configuration and maintains its own set of related counters. The counters include the current number of connections to each server in the group and the number of failed attempts to pass a request to a server. As a result, the server group configuration cannot be modified dynamically.<\/p>\n<p>When the\u00a0<code>zone<\/code>\u00a0directive is included in an\u00a0<code>upstream<\/code>\u00a0block, the configuration of the upstream group is kept in a memory area shared among all worker processes. This scenario is dynamically configurable, because the worker processes access the same copy of the group configuration and utilize the same related counters.<\/p>\n<p>The\u00a0<code>zone<\/code>\u00a0directive is mandatory for\u00a0<a href=\"https:\/\/docs.nginx.com\/nginx\/admin-guide\/load-balancer\/http-load-balancer\/#health_active\">active health checks<\/a>\u00a0and\u00a0<a href=\"https:\/\/docs.nginx.com\/nginx\/admin-guide\/load-balancer\/dynamic-configuration-api\/\">dynamic reconfiguration<\/a>\u00a0of the upstream group. However, other features of upstream groups can benefit from the use of this directive as well.<\/p>\n<p>For example, if the configuration of a group is not shared, each worker process maintains its own counter for failed attempts to pass a request to a server (set by the\u00a0<a href=\"https:\/\/docs.nginx.com\/nginx\/admin-guide\/load-balancer\/http-load-balancer\/#health_passive\">max_fails<\/a>\u00a0parameter). In this case, each request gets to only one worker process. When the worker process that is selected to process a request fails to transmit the request to a server, other worker processes don\u2019t know anything about it. While some worker process can consider a server unavailable, others might still send requests to this server. For a server to be definitively considered unavailable, the number of failed attempts during the timeframe set by the\u00a0<code>fail_timeout<\/code>\u00a0parameter must equal\u00a0<code>max_fails<\/code>\u00a0multiplied by the number of worker processes. On the other hand, the\u00a0<code>zone<\/code>\u00a0directive guarantees the expected behavior.<\/p>\n<p>Similarly, the\u00a0<a href=\"https:\/\/docs.nginx.com\/nginx\/admin-guide\/load-balancer\/http-load-balancer\/#method\">Least Connections<\/a>\u00a0load\u2011balancing method might not work as expected without the\u00a0<code>zone<\/code>\u00a0directive, at least under low load. This method passes a request to the server with the smallest number of active connections. If the configuration of the group is not shared, each worker process uses its own counter for the number of connections and might send a request to the same server that another worker process just sent a request to. However, you can increase the number of requests to reduce this effect. Under high load requests are distributed among worker processes evenly, and the\u00a0<code>Least Connections<\/code>\u00a0method works as expected.<\/p>\n<p>&nbsp;<\/p>\n<h3 id=\"setting-the-zone-size\">Setting the Zone Size<\/h3>\n<p>It is not possible to recommend an ideal memory\u2011zone size, because usage patterns vary widely. The required amount of memory is determined by which features (such as\u00a0<a href=\"https:\/\/docs.nginx.com\/nginx\/admin-guide\/load-balancer\/http-load-balancer\/#sticky\">session persistence<\/a>,\u00a0<a href=\"https:\/\/docs.nginx.com\/nginx\/admin-guide\/load-balancer\/http-load-balancer\/#health_active\">health checks<\/a>, or\u00a0<a href=\"https:\/\/docs.nginx.com\/nginx\/admin-guide\/load-balancer\/http-load-balancer\/#resolve\">DNS re\u2011resolving<\/a>) are enabled and how the upstream servers are identified.<\/p>\n<p>As an example, with the\u00a0<code>sticky_route<\/code>\u00a0session persistence method and a single health check enabled, a 256\u2011KB zone can accommodate information about the indicated number of upstream servers:<\/p>\n<ul>\n<li>128 servers (each defined as an IP\u2011address:port pair)<\/li>\n<li>88 servers (each defined as hostname:port pair where the hostname resolves to a single IP address)<\/li>\n<li>12 servers (each defined as hostname:port pair where the hostname resolves to multiple IP addresses)<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2 id=\"configuring-http-load-balancing-using-dns\">Configuring HTTP Load Balancing Using DNS<\/h2>\n<p>The configuration of a server group can be modified at runtime using DNS.<\/p>\n<p>For servers in an upstream group that are identified with a domain name in the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#server\" target=\"_blank\" rel=\"noopener\"><code>server<\/code><\/a>\u00a0directive, NGINX Plus can monitor changes to the list of IP addresses in the corresponding DNS record, and automatically apply the changes to load balancing for the upstream group, without requiring a restart. This can be done by including the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_core_module.html#resolver\" target=\"_blank\" rel=\"noopener\"><code>resolver<\/code><\/a>\u00a0directive in the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_core_module.html#http\" target=\"_blank\" rel=\"noopener\"><code>http<\/code><\/a>\u00a0block along with the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#resolve\" target=\"_blank\" rel=\"noopener\"><code>resolve<\/code><\/a>\u00a0parameter to the\u00a0<code>server<\/code>\u00a0directive:<\/p>\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">http<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">resolver<\/span> <span class=\"mi\">10<\/span><span class=\"s\">.0.0.1<\/span> <span class=\"s\">valid=300s<\/span> <span class=\"s\">ipv6=off<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">resolver_timeout<\/span> <span class=\"s\">10s<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">server<\/span> <span class=\"p\">{<\/span>\r\n        <span class=\"kn\">location<\/span> <span class=\"s\">\/<\/span> <span class=\"p\">{<\/span>\r\n            <span class=\"kn\">proxy_pass<\/span> <span class=\"s\">http:\/\/backend<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"p\">}<\/span>\r\n    <span class=\"p\">}<\/span>\r\n    <span class=\"kn\">upstream<\/span> <span class=\"s\">backend<\/span> <span class=\"p\">{<\/span>\r\n        <span class=\"kn\">zone<\/span> <span class=\"s\">backend<\/span> <span class=\"mi\">32k<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"kn\">least_conn<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"c1\"># ...\r\n<\/span>        <span class=\"kn\">server<\/span> <span class=\"s\">backend1.example.com<\/span> <span class=\"s\">resolve<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"kn\">server<\/span> <span class=\"s\">backend2.example.com<\/span> <span class=\"s\">resolve<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"p\">}<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<p>In the example, the\u00a0<code>resolve<\/code>\u00a0parameter to the\u00a0<code>server<\/code>\u00a0directive tells NGINX Plus to periodically re\u2011resolve the\u00a0<strong>backend1.example.com<\/strong>\u00a0and\u00a0<strong>backend2.example.com<\/strong>\u00a0domain names into IP addresses.<\/p>\n<p>The\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_core_module.html#resolver\" target=\"_blank\" rel=\"noopener\"><code>resolver<\/code><\/a>\u00a0directive defines the IP address of the DNS server to which NGINX Plus sends requests (here,\u00a0<code>10.0.0.1<\/code>). By default, NGINX Plus re\u2011resolves DNS records at the frequency specified by time\u2011to\u2011live (TTL) in the record, but you can override the TTL value with the\u00a0<code>valid<\/code>\u00a0parameter; in the example it is\u00a0<code>300<\/code>\u00a0seconds, or\u00a0<code>5<\/code>\u00a0minutes.<\/p>\n<p>The optional\u00a0<code>ipv6=off<\/code>\u00a0parameter means only IPv4 addresses are used for load balancing, though resolving of both IPv4 and IPv6 addresses is supported by default.<\/p>\n<p>If a domain name resolves to several IP addresses, the addresses are saved to the upstream configuration and load balanced. In our example, the servers are load balanced according to the\u00a0<a href=\"https:\/\/docs.nginx.com\/nginx\/admin-guide\/load-balancer\/http-load-balancer\/#method\">Least Connections<\/a>\u00a0load\u2011balancing method. If the list of IP addresses for a server has changed, NGINX Plus immediately starts load balancing across the new set of addresses.<\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"load-balancing-of-microsoft-exchange-servers\">Load Balancing of Microsoft Exchange Servers<\/h2>\n<p>In\u00a0<a href=\"https:\/\/docs.nginx.com\/nginx\/releases\/#r7\">NGINX Plus R7<\/a>\u00a0and later, NGINX Plus can proxy Microsoft Exchange traffic to a server or a group of servers and load balance it.<\/p>\n<p>To set up load balancing of Microsoft Exchange servers:<\/p>\n<ol>\n<li>In a\u00a0<code>location<\/code>\u00a0block, configure proxying to the upstream group of Microsoft Exchange servers with the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_proxy_module.html#proxy_pass\" target=\"_blank\" rel=\"noopener\"><code>proxy_pass<\/code><\/a>\u00a0directive:\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">location<\/span> <span class=\"s\">\/<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"kn\">proxy_pass<\/span> <span class=\"s\">https:\/\/exchange<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"c1\"># ...\r\n<\/span><span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<\/li>\n<li>In order for Microsoft Exchange connections to pass to the upstream servers, in the\u00a0<code>location<\/code>\u00a0block set the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_proxy_module.html#proxy_http_version\" target=\"_blank\" rel=\"noopener\"><code>proxy_http_version<\/code><\/a>\u00a0directive value to\u00a0<code>1.1<\/code>, and the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_proxy_module.html#proxy_set_header\" target=\"_blank\" rel=\"noopener\"><code>proxy_set_header<\/code><\/a>\u00a0directive to\u00a0<code>Connection \"\"<\/code>, just like for a keepalive connection:\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">location<\/span> <span class=\"s\">\/<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"c1\"># ...\r\n<\/span>    <span class=\"kn\">proxy_http_version<\/span> <span class=\"mi\">1<\/span><span class=\"s\">.1<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"kn\">proxy_set_header<\/span>   <span class=\"s\">Connection<\/span> <span class=\"s\">\"\"<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"c1\"># ...\r\n<\/span><span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<\/li>\n<li>In the\u00a0<code>http<\/code>\u00a0block, configure a upstream group of Microsoft Exchange servers with an\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#upstream\" target=\"_blank\" rel=\"noopener\"><code>upstream<\/code><\/a>\u00a0block named the same as the upstream group specified with the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_proxy_module.html#proxy_pass\" target=\"_blank\" rel=\"noopener\"><code>proxy_pass<\/code><\/a>\u00a0directive in Step 1. Then specify the\u00a0<a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html#ntlm\" target=\"_blank\" rel=\"noopener\"><code>ntlm<\/code><\/a>\u00a0directive to allow the servers in the group to accept requests with NTLM authentication:\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">http<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"c1\"># ...\r\n<\/span>    <span class=\"kn\">upstream<\/span> <span class=\"s\">exchange<\/span> <span class=\"p\">{<\/span>\r\n        <span class=\"kn\">zone<\/span> <span class=\"s\">exchange<\/span> <span class=\"mi\">64k<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"kn\">ntlm<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"c1\"># ...\r\n<\/span>    <span class=\"p\">}<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<\/li>\n<li>Add Microsoft Exchange servers to the upstream group and optionally specify a\u00a0<a href=\"https:\/\/docs.nginx.com\/nginx\/admin-guide\/load-balancer\/http-load-balancer\/#method\">load\u2011balancing method<\/a>:\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">http<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"c1\"># ...\r\n<\/span>    <span class=\"kn\">upstream<\/span> <span class=\"s\">exchange<\/span> <span class=\"p\">{<\/span>\r\n        <span class=\"kn\">zone<\/span> <span class=\"s\">exchange<\/span> <span class=\"mi\">64k<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"kn\">ntlm<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"kn\">server<\/span> <span class=\"s\">exchange1.example.com<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"kn\">server<\/span> <span class=\"s\">exchange2.example.com<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"c1\"># ...\r\n<\/span>    <span class=\"p\">}<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h3 id=\"complete-ntlm-example\">Complete NTLM Example<\/h3>\n<div class=\"highlight\">\n<pre class=\"chroma\"><code class=\"language-nginx\" data-lang=\"nginx\"><span class=\"k\">http<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"c1\"># ...\r\n<\/span>    <span class=\"kn\">upstream<\/span> <span class=\"s\">exchange<\/span> <span class=\"p\">{<\/span>\r\n        <span class=\"kn\">zone<\/span> <span class=\"s\">exchange<\/span> <span class=\"mi\">64k<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"kn\">ntlm<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"kn\">server<\/span> <span class=\"s\">exchange1.example.com<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"kn\">server<\/span> <span class=\"s\">exchange2.example.com<\/span><span class=\"p\">;<\/span>\r\n    <span class=\"p\">}<\/span>\r\n    \r\n    <span class=\"kn\">server<\/span> <span class=\"p\">{<\/span>\r\n        <span class=\"kn\">listen<\/span>              <span class=\"mi\">443<\/span> <span class=\"s\">ssl<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"kn\">ssl_certificate<\/span>     <span class=\"s\">\/etc\/nginx\/ssl\/company.com.crt<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"kn\">ssl_certificate_key<\/span> <span class=\"s\">\/etc\/nginx\/ssl\/company.com.key<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"kn\">ssl_protocols<\/span>       <span class=\"s\">TLSv1<\/span> <span class=\"s\">TLSv1.1<\/span> <span class=\"s\">TLSv1.2<\/span><span class=\"p\">;<\/span>\r\n       \r\n        <span class=\"kn\">location<\/span> <span class=\"s\">\/<\/span> <span class=\"p\">{<\/span>\r\n            <span class=\"kn\">proxy_pass<\/span>         <span class=\"s\">https:\/\/exchange<\/span><span class=\"p\">;<\/span>\r\n            <span class=\"kn\">proxy_http_version<\/span> <span class=\"mi\">1<\/span><span class=\"s\">.1<\/span><span class=\"p\">;<\/span>\r\n            <span class=\"kn\">proxy_set_header<\/span>   <span class=\"s\">Connection<\/span> <span class=\"s\">\"\"<\/span><span class=\"p\">;<\/span>\r\n        <span class=\"p\">}<\/span>\r\n    <span class=\"p\">}<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<\/div>\n<p>For more information about configuring Microsoft Exchange and NGINX Plus, see the\u00a0<a href=\"https:\/\/docs.nginx.com\/nginx\/deployment-guides\/load-balance-third-party\/microsoft-exchange\/\">Load Balancing Microsoft Exchange Servers with NGINX Plus<\/a>\u00a0deployment guide.<\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"dynamic-configuration-using-the-nginx-plus-api\">Dynamic Configuration Using the NGINX Plus API<\/h2>\n<p>With NGINX Plus, the configuration of an upstream server group can be modified dynamically using the NGINX Plus API. A configuration command can be used to view all servers or a particular server in a group, modify parameter for a particular server, and add or remove servers. For more information and instructions, see\u00a0<a href=\"https:\/\/docs.nginx.com\/nginx\/admin-guide\/load-balancer\/dynamic-configuration-api\/\">Configuring Dynamic Load Balancing with the NGINX Plus API<\/a>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Load balance HTTP traffic across web or application server groups, with several algorithms and advanced features like slow-start and session persistence. &nbsp; Overview Load balancing across multiple application instances is a commonly used technique for optimizing resource utilization, maximizing throughput, reducing latency, and ensuring fault\u2011tolerant configurations. Watch the\u00a0NGINX Plus for Load Balancing and Scaling\u00a0webinar on demand for a deep dive on techniques that NGINX users employ to build large\u2011scale, highly available web services. NGINX and NGINX Plus can be used in different deployment scenarios as a\u00a0very efficient HTTP load balancer. &nbsp; Proxying HTTP Traffic to a Group of Servers To\u2026<\/p>\n","protected":false},"author":1,"featured_media":19,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-18","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-teknologi"],"blocksy_meta":"","_links":{"self":[{"href":"http:\/\/kul.my.id\/w\/wp-json\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/kul.my.id\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/kul.my.id\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/kul.my.id\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/kul.my.id\/w\/wp-json\/wp\/v2\/comments?post=18"}],"version-history":[{"count":2,"href":"http:\/\/kul.my.id\/w\/wp-json\/wp\/v2\/posts\/18\/revisions"}],"predecessor-version":[{"id":30,"href":"http:\/\/kul.my.id\/w\/wp-json\/wp\/v2\/posts\/18\/revisions\/30"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/kul.my.id\/w\/wp-json\/wp\/v2\/media\/19"}],"wp:attachment":[{"href":"http:\/\/kul.my.id\/w\/wp-json\/wp\/v2\/media?parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/kul.my.id\/w\/wp-json\/wp\/v2\/categories?post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/kul.my.id\/w\/wp-json\/wp\/v2\/tags?post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}