Nginx使用动态主机将http重定向到https

Nginx使用动态主机将http重定向到https,nginx,Nginx,我的问题是一般性的。我正在设置Nginx配置文件,它应该支持不同的域名。我应该如何将http重定向到https以支持不同的域名 这是我的配置 server { listen 80; server_name test-server; return 301 https://$server_name$request_uri; } server { listen 443 ssl; server_na

我的问题是一般性的。我正在设置Nginx配置文件,它应该支持不同的域名。我应该如何将
http
重定向到
https
以支持不同的域名

这是我的配置

server {
    listen         80;
    server_name    test-server;
    return         301 https://$server_name$request_uri;
}

server {
    listen              443 ssl;
    server_name         test-server;
      // ssl configurations
}
结果应该是

curl -I http://awesomedomain.com
HTTP/1.1 301 Moved Permanently
Server: nginx/1.8.0
Date: Thu, 21 Apr 2016 08:30:08 GMT
Content-Type: text/html
Content-Length: 184
Location: https://awesomedomain.com/
Connection: keep-alive

curl -I http://helloworld.com
HTTP/1.1 301 Moved Permanently
Server: nginx/1.8.0
Date: Thu, 21 Apr 2016 08:30:08 GMT
Content-Type: text/html
Content-Length: 184
Location: https://helloworld.com/
Connection: keep-alive

使用
$host
变量代替
$server\u name
@AlexeyTen I,如果用
$server\u name
点击,它将重定向到
https://test-server
。它应该是
https://domain.com
你看过我的评论了吗?@AlexeyTen。谢谢,它有效:)