如何使用Nginx proxy_pass保留请求URL [英] How to preserve request url with nginx proxy_pass
问题描述
我正尝试使用 Thin 应用服务器,并且出现一个问题.
I was trying to use Thin app server and had one issue.
当nginx 代理使用proxy_pass http://my_app_upstream;
收到对Thin(或Unicorn)的请求时,应用程序会收到由nginx(http://my_app_upstream
)发送的修改后的URL.
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的文档说:
如果有必要在URI中传输URI 未经处理的形式然后指令 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屋!