- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 nginx.conf 文件当前直接定义了路由:
worker_processes auto;
events { worker_connections 1024; }
http {
upstream wordSearcherApi {
least_conn;
server api1:61370 max_fails=3 fail_timeout=30s;
server api2:61370 max_fails=3 fail_timeout=30s;
server api3:61370 max_fails=3 fail_timeout=30s;
}
server {
listen 80;
server_name server_name 0.0.0.0;
location / {
proxy_pass http://wordSearcherApi;
}
}
}
有没有办法在 docker-compose.yml 中仅创建一个服务 docker-compose up --scale api=3
, nginx 是否做自动负载均衡?
最佳答案
动态上游在 Nginx 中是可能的(正常,无 Plus),但有技巧和限制。
您放弃 upstream
指令并使用普通的 proxy_pass
。
它提供了循环负载平衡和故障转移,但没有 the directive 的额外功能例如权重、故障模式、超时等。
您的上游主机名必须通过变量传递给 proxy_pass
,并且您必须提供解析器
。
它强制 Nginx 重新解析主机名(针对 Docker 网络的 DNS)。
您会丢失与尾部斜杠相关的location
/proxy_pass
行为。
在反向代理到裸 /
的情况下,就像问题中那样,这并不重要。否则,您必须手动重写
路径(请参阅下面的引用资料)。
让我们看看它是如何工作的。
docker-compose.yml
version: '2.2'
services:
reverse-proxy:
image: nginx:1.15-alpine
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
ports:
- 8080:8080
app:
# A container that exposes an API to show its IP address
image: containous/whoami
scale: 4
nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
access_log /dev/stdout;
error_log /dev/stderr;
server {
listen 8080;
server_name localhost;
resolver 127.0.0.11 valid=5s;
set $upstream app;
location / {
proxy_pass http://$upstream:80;
}
}
}
然后...
docker-compose up -d
seq 10 | xargs -I -- curl -s localhost:8080 | grep "IP: 172"
...生成类似以下内容的内容,表明请求分布在 4 个 app
容器中:
IP: 172.30.0.2
IP: 172.30.0.2
IP: 172.30.0.3
IP: 172.30.0.3
IP: 172.30.0.6
IP: 172.30.0.5
IP: 172.30.0.3
IP: 172.30.0.6
IP: 172.30.0.5
IP: 172.30.0.5
引用文献:
Traefik 直接依赖于 Docker API,可能是一个更简单、更可配置的选项。让我们看看它的实际效果。
docker-compose.yml
version: '2.2'
services:
reverse-proxy:
image: traefik
# Enables the web UI and tells Traefik to listen to docker
command: --api --docker
ports:
- 8080:80
- 8081:8080 # Traefik's web UI, enabled by --api
volumes:
# So that Traefik can listen to the Docker events
- /var/run/docker.sock:/var/run/docker.sock
app:
image: containous/whoami
scale: 4
labels:
- "traefik.frontend.rule=Host:localhost"
然后...
docker-compose up -d
seq 10 | xargs -I -- curl -s localhost:8080 | grep "IP: 172"
...还产生一些输出,表明请求分布在 4 个 app
容器中:
IP: 172.31.0.2
IP: 172.31.0.5
IP: 172.31.0.6
IP: 172.31.0.4
IP: 172.31.0.2
IP: 172.31.0.5
IP: 172.31.0.6
IP: 172.31.0.4
IP: 172.31.0.2
IP: 172.31.0.5
在 Traefik UI(示例中的 http://localhost:8081/dashboard/
)中,您可以看到它识别了 4 个 app
容器:
引用文献:
关于docker-compose --scale X nginx.conf 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50203408/
我正在尝试在 View 中同时使用 scalegesture 监听器和 gesturelistener。如果比例为 1,则一切正常,但如果将比例设置为其他值,图像会跳到一个新位置,然后平滑缩放。 我的
我在使用 Canvas 和 canvas.scale(Scale, Scale) 时遇到图像质量问题;它们看起来完全像下面这样: android:运行时调整大小的图像质量 我相信我已经阅读了所有关于调
我有一个使用 svg 过滤器附加阴影的 svg 图形。我需要缩放阴影,但找不到可以执行此操作的过滤器。有谁知道这是否可能?
我正在构建一个逻辑回归分类器。 我从一组 500.000 条记录开始,我只想使用其中的一个样本。 你有什么建议: 1) 缩放总体然后采样2)缩放样本3) 仅缩放样本的 X_TRAIN 分割? 为什么?
我有一个功能,我用它在鼠标进入时放大图片并在鼠标离开时返回到正常大小。问题是,如果我在允许图片返回正常大小之前快速将鼠标移出然后将鼠标移入,那么图片将从鼠标输入时当前的任何大小放大(x2.7) (并且
可以在 scale-y-2 中使用 zoomtovalues 吗?我在多个 y 轴上有几个系列,我想将每个 scale-y-n 缩放到特定值,但我不知道如何... 谢谢和问候, 最佳答案 我们在最近的
我正在尝试在 Android 中创建(我认为是)一个相对简单的动画。也就是说,我想让某个 TextView 在单击按钮时缩小到 0 并返回到 1。当我单击该按钮时实际发生的是 TextView 立即缩
我有一个元素需要缩放到父元素的 100%。因为该元素包含基于像素的动画和可以缩放的图像,所以我不能使用百分比。有没有办法使用 css transform scale 来做到这一点? 最佳答案 相对 c
我在 ChartJS 中遇到一个奇怪的错误并且不知道如何修复它,由于这个错误我无法更改比例的任何内容。 我的代码(Sensor.tsx): import { useParams } from "sol
我有一些数据,我正试图通过不断增加的分母来准确和精确地处理这些数据。 请假设分子总是有小数。 我在 docs 中看到divide(BigDecimal divisor) 实际上会减小比例,这看起来很奇
喂, https://jsfiddle.net/jbwq6y87/7/ #box { width: 500px; height: 500px; transition: 0.5s; ov
几个 Tk 小部件也存在于 Ttk 版本中。通常它们具有相同的一般行为,但使用“样式”和“主题”而不是每个实例的外观属性(例如 bg 等)。这很好,因为 Ttk 小部件默认采用操作系统窗口管理器的“标
我尝试转换视频并使用 scale=-1:720 调整其大小,但出现错误“宽度不能被 2 整除”。我解决了这个问题:scale=-2:720。 之间有什么区别 scale=-1:720 和 scale=
我正在尝试重新创建此 codepen变换:我网站上特定页面的缩放转换,但它没有按预期工作 - 正如您在此代码片段中看到的那样(在整页上查看) - 图像覆盖/覆盖不足和不稳定而不是平滑。 /* Part
我有 3 个 Scale 小部件 scale1、scale2 和 scale3。我想使用 scale1 按以下方式控制 scale2 和 scale3 的值: 我不希望 scale2 和 scale3
我目前正在将我的数据分析从 R 转移到 Python。在 R 中缩放数据集时,我会使用 R.scale(),据我所知,它会执行以下操作:(x-mean(x))/sd(x) 为了替换该函数,我尝试使用
从文档中,定义为: 量化 ..a variant of linear scales with a discrete rather than continuous range. The input do
我有一个时基折线图,我正在尝试获取点击坐标处每个刻度的值。 我在 ChartJS 选项中指定的 onClick 函数: onClick: function(event, elementsAtEvent
我见过这样写的代码: ,但我也看到过这样写的代码: initial-scale=1 和 initial-scale=1.0 有区别吗? 最佳答案 没有。 specification描述视口(viewp
给定 y 轴 (s) 上的缩放和 x 轴 (t) 上的平移参数,当目的是最大化曲线叠加(而不是最小化距离)时,如何缩放和对齐两条不重合的曲线? 正如 @DWin 所指出的,这可能会被重新命名为“如何使
我是一名优秀的程序员,十分优秀!