nginx:正则表达式在重写中不起作用

nginx: regex not working in rewrite

我有http://sample.cervo02.com。我正在尝试获取 https://cervo02.com/sample.

我尝试了几个重定向 none,其中的一些都有效。 rewrite ^([^.]*)$ https://cervo02.com/ last; return https://cervo02.com//

另外一个是rewrite ^(.*).cervo02.com$ https://cervo02.com/ last;return一个404url没有改写

欢迎任何帮助再次感谢。

重写处理 URI,而不是 URL。 试试这个

server {
  server_name ~ ^(?<subdomain>.*)\.cervo02\.com$;

  rewrite ^ https://cervo02.com/$subdomain$request_uri$is_args$args;
}