是否可以将这些主机合二为一?
server {
server_name www.website.com;
rewrite ^ http://website.com$request_uri? permanent;
}
server {
server_name www.website.ru;
rewrite ^ http://website.ru$request_uri? permanent;
}
是否可以将这些主机合二为一?
server {
server_name www.website.com;
rewrite ^ http://website.com$request_uri? permanent;
}
server {
server_name www.website.ru;
rewrite ^ http://website.ru$request_uri? permanent;
}
是的,以下应该有效:
server {
server_name www.website.com website.com www.website.ru website.ru;
if ( $host ~ "www\.(.*)" ) {
set $hostdomain $1;
rewrite ^ $scheme://$hostdomain$request_uri? permanent;
}
# handling of the non-rewritten non-www requests goes here
}
注意:您需要保存 domain-minus-www 而不是直接在 rewrite 中使用 $1 的原因是因为 rewrite 指令重置了捕获变量