问题原文
原帖链接 · Forrest Wilkins · CC BY-SA 3.0
When using multiple domain names for one server, how do you get the domain name currently being used in a request? I'm using the embedded variables for Nginx in it's configuration file.
I've set up OpenSSL and have a redirect that works fine for my first domain since, as you can see, I'm explicitly redirecting to it at the bottom of my config file. So an HTTP request on any of the other domains redirects to that first one for a secure connection. Is there an embedded variable I can use, similar to $request_uri, for example, but just returns the given domain name used by the client?
Here's the server block where I'm running the redirect.
server {
listen 80;
listen [::]:80;
server_name example.com example1.com example2.com example3.com;
location / {
return 301 https://example.com$request_uri;
}
}
And the rest of my config: https://pastebin.com/HgnZ0aBe
已采纳解答
原帖链接 · Ilham Sulaksono · CC BY-SA 3.0
Domain name that used in request is basically a host request header. In nginx, variable for host header is $host. So if you want to redirect based on domain name/host you should change the configuration to :
return 301 https://$host$request_uri;
Hope this help . Thanks
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
