server { listen 80; server_name domain.com www.domain.com; if ($host != 'www.domain.com' ) { rewrite ^/(.*)$ http://www.domain.com/$1 permanent; } # 301 跳转到 www.domain.com }