【发布时间】:2020-07-17 18:43:13
【问题描述】:
我的问题如下:
我有 2 个 Web 应用程序,一个“普通”和一个“昂贵”。对于昂贵的任务,“普通”与“昂贵”通信。为了提高速度和减少瓶颈,计划在 2 台不同的机器上部署至少几个“昂贵”应用程序,并使用负载平衡器来拆分请求(而不是拥有 NASA PC,拥有 2 台或更多普通 PC) .
这些应用程序是用 Gunicorn + Django 制作的,并通过带有 Nginx 的套接字提供服务。 (没有 Docker 或奇怪的东西,在很大程度上是一个主管来维持生命)
当前系统运行良好,但对于某些任务它可能会更快,这就是负载平衡器的原因。但是,我无法使用不在同一台机器中的服务器地址(没有 localhost:port、x.x.x.x、x.x.x.x:port 或 /etc/hosts 中包含的 url)使负载均衡器工作
这是一个balancer.conf,它使用本地应用在我的本地工作
upstream balancer {
# least_conn;
server 192.168.22.200:8000;
server 192.168.22.200:8001;
}
server {
listen 80;
server_name localhost;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Protocol $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 120;
proxy_redirect off;
proxy_pass http://balancer;
}
}
这是我最后一次尝试使它与远程服务器一起工作(我需要 SSL 的东西,因为它是强制在它们上的)
upstream balancer {
# least_conn;
server external.machine.com;
}
server {
listen 80;
server_name test.url.com;
return 301 https://$server_name$1;
}
server {
listen 443 ssl http2;
server_name test.url.com;
# Turn on SSL
ssl on;
<exactly the same stuff I have in the others .conf for the ssl>
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
location / {
# proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Protocol $scheme;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_read_timeout 120;
# proxy_redirect off;
proxy_pass http://balancer;
}
}
澄清并记住:external.machine.com 和 test.url.com 不在同一台机器上。他们有不同的公共 IP。在 external.machine.com 中,我已经配置了一个 Nginx,它可以正确地为“昂贵”的应用程序提供服务。
我找不到任何相关的或尝试过的人,我发现的所有单个帖子或文档都与本地 IP 相关或完成,而不是外部 IP 的常规 URL。
所以我现在有一个问题,是否可以将 Nginx 负载均衡器与远程 IP 或仅与本地 IP 一起使用
【问题讨论】:
标签: nginx load-balancing