mongodb - 如何在 nginx 容器中启用流模块
问题描述
我想在 nginx 后面代理 mongodb。我出于同样的目的遇到了以下代码。
我的问题是,如何在 nginx 中启用“流”模块?
stream {
server {
listen 27020;
proxy_connect_timeout 5s;
proxy_timeout 20s;
proxy_pass mongodb_host;
}
upstream mongodb_host{
server xx.xxx.xxx.xx:27017;
}
}
解决方案
根据 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
在包含您的代码的“/usr/local/nginx/conf/stream”目录中创建 1 个或多个文件stream { ... }
。配置文件名只需要以“.conf”扩展名结尾。然后你可以在“/usr/local/nginx/conf/http”中创建任何http配置文件。
推荐阅读
- swift - class_getInstanceMethod 正在返回 nil
- java - 从另一个文件调用方法作为Java中的字符串
- php - 如何根据php中mysql服务器的数据计算日期时间
- ios - 修改抽象结构中的值
- python - 如何使用 io 在内存中将数据流生成为文件之类的对象?
- workflow - 工作流程条件 Liferay 7.1 表单
- angularjs - 如果我传递 api,Angular 服务不会返回任何值
- ios - 转换为纹理时,UIImage 的透明度丢失
- apache-spark - Spark 1.6 DataFrame 优化连接分区
- python - Networkx 根本不工作 - 最基本操作的奇怪错误