第一种方法\r\nserver {\r\nserver_name www.example.com example.com ;\r\nif ($host != 'www.example.com' ) {\r\nrewrite ^/(.*)$ http://www.example.com/$1 permanent;\r\n}\r\n\r\n}\r\n第二种方法:\r\n\r\nserver {\r\nserver_name example.com;\r\nrewrite ^/(.*) http://www.example.com/$1 permanent;\r\n}\r\n\r\n重新载入配置\r\n\r\nnginx -t && nginx -s reload