我的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;
}
]
答案 0 :(得分:1)
如何重定向到外部https网站?
如果要重定向,则不应使用代理密码。只需使用return 301;
location /admin {
return 301 https://admin.myothersite.com/httpsms;
}