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