Configure Nginx as a TCP Load Balancer

I want to use Nginx 1.9 for load balancing TCP. I completed the tutorial at https://www.nginx.com/resources/admin-guide/tcp-load-balancing/ but it did not work.

Every time I tried to run nginx, I had errors:

nginx: [emerg] unknown directive "stream" in /opt/nginx/nginx.conf 

Here is my nginx.conf file:

 events { worker_connections 1024; } http { # blah blah blah } stream { upstream backend { server 127.0.0.1:9630; server 127.0.0.1:9631; } server { listen 2802; proxy_connect_timeout 1s; proxy_timeout 3s; proxy_pass backend; } } 

Could you tell me how to configure it correctly?

+5
source share
3 answers

The best way is to collect nginx from the source to support the stream directive:

 ./configure --prefix=/opt/nginx --sbin-path=/usr/sbin/nginx --conf-path=/opt/nginx/nginx.conf --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --with-http_ssl_module --with-threads --with-stream --with-http_slice_module make sudo make install 
+8
source

Using Homebrew on OS X, this can be done with

 brew install nginx-full --with-stream 

This may require you to install the homebrew-nginx faucet first, in which case you may need to run

 brew install homebrew/nginx/nginx-full --with-stream 

to make sure the crane will be installed first.

+5
source

If you are using linux, the standard nginx repositories .

0
source

Source: https://habr.com/ru/post/1239907/


All Articles