问题原文
原帖链接 · Andras · CC BY-SA 3.0
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?
已采纳解答
原帖链接 · wilee · CC BY-SA 3.0
Hopefully not too little too (eight months!) late. I had a similar question myself, to use the original request port in nginx.conf.
$http_name: arbitrary request header field; the last part of a variable name is the field name converted to lower case with dashes replaced by underscores
$http_host should therefore contain the request 'Host' header, if that helps.
e.g. localhost:8020
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
