A question of configuring proxy redirect from http to https

Here is my configuration scenario.
One nginx host and several upstream servers.
For the upstream server, giving a request with URL “/abc”, it will
redirect to “/abc/”.

The nginx config is:

upstream ups {
server xxxxxxx;
server xxxxxxx;

}

location / {
proxy_pass ups;
proxy_add_header $host:$server_port;
}

Therefore, if user access

http://<nginx_host>:<nginx_port>/abc;

the upstream server will send the redirection:
Location: http://<nginx_host>:<nginx_port>/abc/

Here everything looks fine.

But there is an extreme case:
if nginx listen on https rather than http. I have to use something like
“proxy_redirect http://$host:$server_port /” to convert http to https in
the redirection Location URL. But for now proxy_redirect doesn’t support
var in the first arg. Maybe you will say the first arg of proxy_redirect
could be a plain literal. But users could use various ways to access
nginx, like FQDN, host name, IP address (maybe multiple ones), localhost
or some. So I have to write proxy_redirect for each possibilities. Is
this the best way I can do?

Posted at Nginx Forum: