Part of my nginx conf.d as shown below. proxy_pass to internal networks working. Cant redirect to external site.
I need to redirect this
$host = my.website.com/admin to proxy_pass "https://admin.myothersite.com/httpsms";
and I am keep getting 404 error.
How to redirect to external https site?
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;
}
]
How to redirect to external https site?
if you want to redirect you shouldnt use proxy pass. just use return 301;
location /admin {
return 301 https://admin.myothersite.com/httpsms;
}