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?
Load balancing refers to efficiently distributing network traffic across multiple backend servers. In NGINX Plus Release 5 and later, NGINX Plus can proxy and load balance Transmission Control Protocol) (TCP) traffic.
It is possible to use nginx as a very efficient HTTP load balancer to distribute traffic to several application servers and to improve performance, scalability and reliability of web applications with nginx.
Along with HTTP traffic, NGINX Ingress Controller load balances TCP and UDP traffic, so you can use it to manage traffic for a wide range of apps and utilities based on those protocols, including: MySQL, LDAP, and MQTT – TCP‑based apps used by many popular applications.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With