nginx rewrite 实现二级域名跳转
server { listen 80;server_name *.test.com;
root /usr/local/www;
location ~ ^/(test|images|styles)/ 这是里可以加多个目录,如果不加目录,会无法访问到abc.test.com/目录下的文件,如图片目录/images
{
proxy_redirect off;
proxy_set_header Host www.test.com;
proxy_pass http://192.168.1.2:8080;
}
location / {
set $domain default;
if ( $http_host ~* "^(.*)\.test\.com$") {
set $domain $1;
}
rewrite ^/(.*) /test/$domain/$1 last;
}
}
access_log off;
}
页:
[1]