1. 程式人生 > >ecs nginx 配置 http 自動跳轉到 https

ecs nginx 配置 http 自動跳轉到 https

1:在 http 模組中先配置所有的 http 訪問都跳轉到 https
  server {
        listen      80 default_server;
        server_name _;
        return 301 https://www.daicooper.com$request_uri;
    }

2:再在 https 模組配置 

 server {
        listen       443 ssl;
        server_name  www.daicooper.com;

        if ( $host = 'daicooper.com' ) {
                rewrite ^/(.*)$ https://www.daicooper.com/$1 permanent;
        }

       。。。。

      。。。。

}
 

訪問測試:

http://daicooper.com  --> https://www.daicooper.com

daicooper.com  --> https://www.daicooper.com

www.daicooper.com  --> https://www.daicooper.com

https://daicooper.com --> https://www.daicooper.com