vhost 的 Nginx 正则表达式变量为空

Nginx regex variable for vhost is null

我有一个如下所示的配置文件:

server {
    listen 80;

    server_name ~^(?<folder>[^.]+).(?<user>[^.]+).example.com;
    charset utf-8;
    index index.php index.html index.htm;
    root /var/www/projects/dev/$user/$folder/htdocs;
...
}

所以我可以使用 url 访问该站点,例如 test.user.example.com。

在一台服务器中,配置文件按预期工作,但在其他服务器中,变量无效。

有什么想法吗?

解决方案是修改

中的正则表达式
server_name ~^(?<folder>[^.]+)\.(?<user>[^.]+).example.com;

server_name ~^(?<folder>[^.]*).(?<user>[^.]*).example.com;