django - NGINX 配置中的 proxy_pass 选项有什么作用?

标签 django nginx amazon-ec2 gunicorn

NGINX proxy_pass 配置有什么作用?例如,假设我有一个托管在 Amazon 的 EC2 服务上的 Django 应用程序。

在 EC2 上,假设我在 2 个 nginx 服务器前面有 1 个负载均衡器。 nginx 服务器指向 4 个使用 Gunicorn 作为 WSGI 服务器的 django 应用服务器:

upstream my-upstream {
 server 12.34.45.65:8000;
 server 13.43.54.56:8000;
 server 13.46.56.52:8000;
 server 14.46.58.51:8000;
}

location / {
proxy_pass http://my-upstream;
}

什么是proxy_pass?在这种情况下是负载均衡器的 URL 吗?

最佳答案

看看nginx's HttpProxyModule ,这就是 proxy_pass 的来源。 proxy_pass docs说:

This directive sets the address of the proxied server and the URI to which location will be mapped.

所以当你告诉 Nginx 到 proxy_pass 时,你是在说“将这个请求传递到这个代理 URL”。

还有关于 upstream 的文档可用:

This directive describes a set of servers, which can be used in directives proxy_pass and fastcgi_pass as a single entity.

所以你使用 upstream 作为 proxy_pass 的原因是因为 proxy_pass 需要一个 URL,但你想传递不止一个(所以你使用上游)。

如果您的负载均衡器位于您的 nginx 之前,则您的负载均衡器 URL 不会在此配置中。

关于django - NGINX 配置中的 proxy_pass 选项有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16111271/

相关文章:

python - 单个 View 中的多个模型(django、python)

python - 如何将值从 html 传递到 python

node.js - POST 参数不会从我的反向代理传递到我的后端服务器

python - Django - 从 geraldo 报告中删除无关的 unicode 符号

python - 如何在本地主机上正确安装 django 注册?

python - docker-compose的nginx和django设置

ubuntu - 如何在 Ubuntu 20.04 服务配置中选择特定版本的 dotnet?

amazon-web-services - 无法删除通过 CloudFormation 模板附加到 EC2 实例的其他 ENI

hadoop - 在AWS EC2上进行Hadoop初始设置?

jenkins - 持续集成 : running Jenkins Build on newly created EC2 Instance using AWS Cloudformation+OpsWorks, 什么是最佳实践?