Nginx 确实重定向,而不是代理 [英] Nginx does redirect, not proxy

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

问题描述

我想将 Nginx 设置为 https 服务的反向代理,因为我们有一个特殊的用例,需要取消 https"连接:

I want to set up Nginx as a reverse proxy for a https service, because we have a special usecase where we need to "un-https" a connection:

http://nginx_server:8080/myserver ==>https://mysecureservice

但是实际的 https 服务没有被代理.Nginx 确实将我重定向到实际服务,因此浏览器中的 URL 会发生变化.我想与 Nginx 交互,因为它是实际的服务,只是没有 https.

But what happens is that the actual https service isn't proxied. Nginx does redirect me to the actual service, so the URL in the browser changes. I want to interact with Nginx as it was the actual service, just without https.

这就是我所拥有的:

server {
    listen 0.0.0.0:8080 default_server;
    location /myserver {
        proxy_pass https://myserver/;
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
    }
}

推荐答案

你必须使用 proxy_redirect 来处理重定向.

You have to use the proxy_redirect to handle the redirection.

 Sets the text that should be changed in the "Location" and "Refresh" header fields of a 
 proxied server response. Suppose a proxied server returned the header field 
 "Location:https://myserver/uri/". The directive
 will rewrite this string to "Location: http://nginx_server:8080/uri/". 

示例:

 proxy_redirect https://myserver/ http://nginx_server:8080/;

来源:http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect

这篇关于Nginx 确实重定向,而不是代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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