简体   繁体   English

nginx 在单个实例上支持 tcp 和 http 代理吗?

[英]does nginx support tcp and http proxy on single instance?

I have a requirement where I have a single nginx instance to act as a VIP for http requests and also the mysql db cluster.我有一个要求,我有一个 nginx 实例来充当 http 请求和 mysql 数据库集群的 VIP。

Is it possible to put the same configs under one host?是否可以将相同的配置放在一台主机下? TCP syntax looks different than the http. TCP 语法看起来与 http 不同。 Please help me with some sample config which will work.请帮我提供一些可以工作的示例配置。

This worked for me.这对我有用。 https://docs.nginx.com/nginx/admin-guide/load-balancer/tcp-udp-load-balancer/ https://docs.nginx.com/nginx/admin-guide/load-balancer/tcp-udp-load-balancer/

http {

  # http content

    }

        upstream servers{
           server server1;
           server server2 backup;
    }
}


stream {
    upstream mygroup {
        least_conn;
        server db_master:3309;
        server db_slave:3309;
    }
    server {
        listen        3309;
        proxy_pass    mygroup;
        proxy_timeout 5s;
        proxy_connect_timeout 1s;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM