I have an nginx server with SSL enabled. As it operates on a different port (than 443), sometimes it receives plain HTTP requests instead of HTTPS. I'd like to set up a redirection for that to replace the scheme automatically, I tried this code:
error_page 497 https://$host:$server_port$request_uri;
But the problem here that as the server operates in a VM and the port is forwarded to a different port, it redirects to an invalid port (from which the server got the request).
My question is: how can I parse/get the port from the request rather than the port from the server received the request?