Configure Nginx to be a TCP load balancer
14,793
Solution 1
The best way is compiling nginx from source to support 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
Solution 2
Using Homebrew on OS X, this can be done with:
brew install nginx-full --with-stream
This might ask you to first install the homebrew-nginx
tap, in which case you might have to run
brew install homebrew/nginx/nginx-full --with-stream
to make sure that the tap gets installed first.
Comments
-
anhldbk almost 2 years
I want to use Nginx 1.9 to be a TCP load balancer. I followed the tutorial in https://www.nginx.com/resources/admin-guide/tcp-load-balancing/ but it didn't work.
Every time I tried to start nginx, I've got 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; } }
Would you pls tell me how to configure it right?