设置.conf文件以允许“通配符”;在URL


Set up .conf file to allow for "wildcard" in URL

不确定这是否可能,但我希望做的是将用户定向到完全相同的目录和文件,而不管他们来自哪个特定的URL路径。

例如,我希望test.mysite.com/person1test.mysite.com/person2来到同一个索引页。

我的.conf (nginx)的一些伪代码:
server {
    listen 80;
   server_name  test.mysite.com/person1; 
   location / {
       root  /home/testing/public_html;
       index index.html; 
     try_files                   $uri $uri/ /index.php?$args; 
       port_in_redirect off;
}

我可以这样做吗:

server {
    listen 80;
   server_name  test.mysite.com/*; //Something here that indicates wildcard
   location / {
       root  /home/testing/public_html;
       index index.html; 
     try_files                   $uri $uri/ /index.php?$args; 
       port_in_redirect off;
}

整个要点是,我将提供"个人"url给人们,包括他们的名字,像这样:test.mysite.com/person1。我将使用javascript获取URL的唯一部分("person1"),并使用它通过PHP等提供自定义内容。

本质上,我不希望URL的最后一部分改变我提供索引文件的目录。

谢谢。

这里的技巧是改变server_name而不是location

server {
   listen 80;
   server_name  ~^(test).*'.mysite'.com$; 
   location / {
   root  /home/testing/public_html;
   index index.html; 
 try_files                   $uri $uri/ /index.php?$args; 
   port_in_redirect off;
}