我想使用 Nginx 1.9 作为 TCP 负载均衡器。我遵循了 https://www.nginx.com/resources/admin-guide/tcp-load-balancing/ 中的教程但它没有用。
每次尝试启动 nginx 时,我都会遇到错误:
nginx: [emerg] unknown directive "stream" in /opt/nginx/nginx.conf
这是我的 nginx.conf 文件:
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;
}
}
你能告诉我如何正确配置它吗?
最佳答案
最好的方法是从源代码编译 nginx 以支持 stream
指令:
./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
关于nginx - 将 Nginx 配置为 TCP 负载均衡器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34615146/