server {
listen 80;
server_name www.xxx.com xxx.com;
if ($host != 'www.xxx.com') {
rewrite ^/(.*)$ http://www.xxx.com/$1 permanent;
}
}
server {
listen 443;
server_name www.xxx.com xxx.com;
if ($host != 'www.xxx.com') {
rewrite ^/(.*)$ https://www.xxx.com/$1 permanent;
}
}
然后重启一下nginx即可。