【发布时间】: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;
}
]
【问题讨论】: