又一个nginx重写规则问题:
如何从http://www.*.domain.com
到http://*.domain.com
重写?
答案 0 :(得分:7)
if ($host ~* www\.(.*)) {
set $host_without_www $1;
rewrite ^(.*)$ http://$host_without_www$1 permanent; # $1 contains '/foo', not 'www.mydomain.com/foo'
}
从服务器故障中回答: https://serverfault.com/questions/139579/nginx-subdomain-rewrite
答案 1 :(得分:2)
server {
listen 80;
listen 443;
server_name ~^www\.(\w+)\.domain\.com$;
location / {
rewrite ^ $scheme://$1.domain.com$request_uri? permanent;
}
}