Nginx 代理重写配置 [英] Nginx proxy rewrite configuration

查看:71
本文介绍了Nginx 代理重写配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以重写 url 并使用代理服务器进行后台连接?

it is possible to rewrite a url and use a proxy server for backgound connection?

一个例子,我想在我的代理服务器上使用这个 URL my.domain.org/demo 并使用 proxy_pass my 将它重定向到我在另一台服务器上的 tomcat 的根目录.tomcat.local.

An example, I want to use this URL my.domain.org/demo on my proxy server and redirect this into the root directory of my tomcat on another server with proxy_pass my.tomcat.local.

url 必须位于 my.domain.org/demo 并且必须使用代理 url my.tomcat.local(没有任何子域).这个钩子可以吗?

The url must be place my.domain.org/demo and must used the proxy url my.tomcat.local (without any subdomains). Is this hook possible?

谢谢!!!!!!

推荐答案

是的,这绝对有可能.

使用以下配置

location /demo {
    proxy_pass http://my.tomcat.local/; #Pay attention to the trailing slash. It MUST be present here.
}

重点是,如果指定的proxy_pass目的地包含路径(单斜线也视为路径),那么Nginx会直接将请求传递到该URL;否则,Nginx 会将接收到的 URL 的路径附加到 proxy_pass 目标并使用生成的 URL.

The point is that if the specified proxy_pass destination contains path (a single slash is also considered as a path), then Nginx will directly pass request to that URL; otherwise, Nginx will append the path of the received URL to the proxy_pass destination and use the resulting URL.

参考:http://wiki.nginx.org/HttpProxyModule#proxy_pass

这篇关于Nginx 代理重写配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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