【问题标题】:how to enable stream module in nginx container如何在 nginx 容器中启用流模块
【发布时间】:2022-01-28 07:37:03
【问题描述】:

我想在 nginx 后面代理 mongodb。我出于同样的目的遇到了以下代码。

我的问题是,如何在 nginx 中启用“stream”模块?

stream {
    server {
        listen 27020;
        proxy_connect_timeout 5s;
        proxy_timeout 20s;
        proxy_pass    mongodb_host;
    }

    upstream mongodb_host{
        server xx.xxx.xxx.xx:27017;
    }
}

【问题讨论】:

  • 你连接mongo服务器的协议是http还是https?
  • mongodb 连接发生在 tcp 调用上..nginx 将获取请求并按原样转发到 mongo,而无需添加 http 协议

标签: mongodb nginx devops nginx-reverse-proxy


【解决方案1】:

根据 nginx 文档,需要使用 --with-stream 选项在技术上重新编译。幸运的是,有很多现有的图像可以用于此目的。我个人用过这个:https://hub.docker.com/r/tekn0ir/nginx-stream

如果使用 compose,您的 docker-compose.yml 文件将如下所示 -

version: '3'  
services:  
    service1:  
        ...  
    service2:  
        ...  
    nginx:  
        image: tekn0ir/nginx-stream:latest  
        ports:   
            - "27020:27020"   
        volumes:   
            - /usr/local/nginx/conf/http:/opt/nginx/http.conf.d
            - /usr/local/nginx/conf/stream:/opt/nginx/stream.conf.d

在包含您的代码stream { ... } 的“/usr/local/nginx/conf/stream”目录中创建 1 个或多个文件。配置文件名只需要以“.conf”扩展名结尾。然后你可以在“/usr/local/nginx/conf/http”中创建任何http配置文件。

【讨论】:

    【解决方案2】:

    直接来自nginx documentation

    “ngx_stream_core_module 模块从 1.9.0 版本开始可用。该模块默认不构建,​​应使用 --with-stream 配置参数启用。”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-10
      • 1970-01-01
      • 1970-01-01
      • 2020-06-25
      • 1970-01-01
      • 2021-01-08
      • 2020-08-03
      • 1970-01-01
      相关资源
      最近更新 更多