【问题标题】:How to redirect to external https site?如何重定向到外部 https 站点?
【发布时间】:2019-10-15 03:08:04
【问题描述】:

我的 nginx conf.d 的一部分如下图所示。 proxy_pass 到内部网络工作。无法重定向到外部站点。

我需要重定向这个

$host = my.website.com/admin 到 proxy_pass "https://admin.myothersite.com/httpsms";

我不断收到 404 错误。

如何重定向到外部 https 站点?

server {

…….
……..
………

 // WORKS
   if ($host =my.website.com/login) {
         return 301 https://$host$request_uri;
   }

// WORKS
   if ($host = my.website.com/admin) {
         return 301 https://$host$request_uri;
   }
}



server {

…….
……..
………


// WORKS
    location /login {
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass "http://127.0.0.1:3000;
        proxy_next_upstream error timeout http_500 http_502 http_503 http_504 http_404;
        proxy_intercept_errors on;
    }


// ITS NOT WORKING
    location /admin {
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass "https://admin.myothersite.com/httpsms";
        proxy_next_upstream error timeout http_500 http_502 http_503 http_504 http_404;
        proxy_intercept_errors on;
    }
]

【问题讨论】:

    标签: nginx proxypass


    【解决方案1】:

    如何重定向到外部 https 站点?

    如果你想重定向你不应该使用代理通行证。只需使用 return 301;

    location /admin {
        return 301 https://admin.myothersite.com/httpsms;
    }
    

    【讨论】:

    • 谢谢,这比我想象的要容易得多。问候
    • @Nick 如果它有效,你应该接受这个作为你的答案。
    • 我做到了,非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-01
    • 2019-07-26
    • 2016-03-05
    • 2012-01-27
    • 2021-06-19
    • 2014-05-26
    相关资源
    最近更新 更多