加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

将Nginx配置为TCP负载均衡器

发布时间:2020-12-13 21:24:10 所属栏目:Nginx 来源:网络整理
导读:我想使用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 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读