如何使用 nginx proxy_pass 保留请求 url [英] How to preserve request url with nginx proxy_pass

查看:80
本文介绍了如何使用 nginx proxy_pass 保留请求 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试使用 Thin 应用服务器时遇到了一个问题.

I was trying to use Thin app server and had one issue.

当 nginx 代理使用 proxy_pass http 向瘦(或独角兽)请求时://my_app_upstream; 应用程序接收到 nginx 发送的修改后的 URL(http://my_app_upstream).

When nginx proxies the request to Thin (or Unicorn) using proxy_pass http://my_app_upstream; the application receives the modified URL sent by nginx (http://my_app_upstream).

我想要的是不加修改地传递原始 URL 和来自客户端的原始请求,因为应用程序严重依赖它.

What I want is to pass the original URL and the original request from client with no modification as the app relies heavily on it.

nginx 的 doc 说:

The nginx' doc says:

如果需要传输URI未处理的表单 then 指令proxy_pass 应该在没有 URI 的情况下使用部分.

If it is necessary to transmit URI in the unprocessed form then directive proxy_pass should be used without URI part.

但我不明白如何准确地配置它,因为相关示例实际上使用的是 URI:

But I don't understand how exactly to configure that as the related sample is actually using URI:

location  /some/path/ {
  proxy_pass   http://127.0.0.1;
}

那么请您帮我弄清楚如何保留来自客户端的原始请求 URL?

So could you please help me figuring out how to preserve the original request URL from the client?

推荐答案

我认为 proxy_set_header 指令可以帮助:

I think the proxy_set_header directive could help:

location / {
    proxy_pass http://my_app_upstream;
    proxy_set_header Host $host;
    # ...
}

这篇关于如何使用 nginx proxy_pass 保留请求 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆