【问题标题】:What does the proxy_pass option in the NGINX config do?NGINX 配置中的 proxy_pass 选项有什么作用?
【发布时间】:2013-04-13 05:44:50
【问题描述】:

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 吗?

【问题讨论】:

    标签: django nginx amazon-ec2 gunicorn


    【解决方案1】:

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

    该指令将代理服务器的地址和 URI 设置为 将映射哪个位置。

    因此,当您将 Nginx 告诉 proxy_pass 时,您是在说“将此请求传递到此代理 URL”。

    还有关于upstream 的文档:

    该指令描述了一组服务器,可用于 将 proxy_pass 和 fastcgi_pass 指令作为一个实体。

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

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

    【讨论】:

      【解决方案2】:

      应该是: proxy_pass http://my-upstream;

      nginx 将对您的 4 个 djano+gunicorn 实例(您的 my-upstream)上的所有请求进行负载平衡。负载均衡器将指向 nginx 服务器。

      【讨论】:

      • 谢谢,这就是我要找的,我会试一试告诉你
      • 这是错误的。除非您添加方案 http/https,否则它会给出错误 - nginx: [emerg] invalid URL prefix in /.../conf/nginx.conf:xx
      猜你喜欢
      • 2017-08-25
      • 2012-12-31
      • 2012-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-23
      相关资源
      最近更新 更多