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/