Configuration General/etc/nginx/vhosts/default-如何指定服务器范围的设置?

Configuration General/etc/nginx/vhosts/default-如何指定服务器范围的设置?,configuration,nginx,settings,Configuration,Nginx,Settings,从我看到的情况来看,如果我写在/etc/nginx/vhosts/default中,效果将是服务器范围的,而不是每个域。我似乎不知道如何编写规则从/index.html或/dir/index.html/ro/或/dir/重定向到服务器范围的效果 问题是,在CentOS上运行会在/home/user/public_html中生成文件,而在nginx中,我看不到在root指令中使用它的用户部分。我想到了这样的事情: --- server { listen 111.111.111.111:80;

从我看到的情况来看,如果我写在/etc/nginx/vhosts/default中,效果将是服务器范围的,而不是每个域。我似乎不知道如何编写规则从/index.html或/dir/index.html/ro/或/dir/重定向到服务器范围的效果

问题是,在CentOS上运行会在/home/user/public_html中生成文件,而在nginx中,我看不到在root指令中使用它的用户部分。我想到了这样的事情:

---
server
{
listen 111.111.111.111:80;           // fake IP
server_name "";                      // this to take in all hosts... ??
root ~^/home/(.*)/public_html;       // this (.*) would contain the user part
rewrite ^(.*/)index.(html|htm) http://$host$1 permanent;
}
---
如你所见。。可能我试图使重定向适用于所有站点,而不必手动编辑每个特定的域conf文件,而是将其保存在/etc/nginx/vhosts/default conf文件中

非常感谢您的帮助:)


谢谢你

你可能需要这样的东西

server {
    server_name   ~^(www\.)?(?<user>.+)\.domain\.com$;

    location / {
        root  /home/$user/public_html;
    }
}
服务器{
服务器名称^(www\.?(?.+)\.domain\.com$;
地点/{
root/home/$user/public\u html;
}
}
此外,您不能在
根目录中使用正则表达式,因为它是一个不匹配的定义。

server_name”“;--用于不带主机的请求:标头