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

时间:2016-04-21 08:44:57

标签: nginx

我的问题是通用的。我正在设置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

0 个答案:

没有答案