案例1
http://example.com http://www.example.com https://example.com
https://www.example.com
server {
listen 80;
server_name example.com www.example.com;
return 301 https://www.example.com$request_uri;
}
server {
listen 443;
server_name example.com www.example.com;
if ($host = example.com) {
return 301 https://www.example.com$request_uri;
}
}
案例2
http://example.com
https://example.com
server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
return 301 https://example.com$request_uri;
}
server {
listen 443;
server_name example.com;
}
扩展
nginx -t
nginx -s reload