nginx 不带www到www域名的重定向

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
server {
    listen       80;
    charset utf-8;
    server_name xxx.com www.xxx.com;
 
    if ($http_host !~ "^www.xxx.com$") {
 
       rewrite ^(.*) http://www.xxx.com$1 permanent;
 
    }
 
    location / {
       proxy_pass http://192.168.0.2:80;
       proxy_set_header Host $host;
    }
 
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}