Nginx如何将regex中的多个位置映射到单个目录

Nginx如何将regex中的多个位置映射到单个目录,nginx,Nginx,我的应用程序使用单个web应用程序(HTML和Javascript)为多个(动态金额)系统提供服务 系统通过类似URL的http://localhost/sites/,其中系统id仅允许小写字母 假设web应用程序位于/opt/myapp中。如何在nginx中配置它 我试过以下方法,但都不管用 location ~ /sites/[a-z]+ { alias /opt/myapp; index index.html index.htm; } 输入http://localhost/

我的应用程序使用单个web应用程序(HTML和Javascript)为多个(动态金额)系统提供服务

系统通过类似URL的
http://localhost/sites/
,其中
系统id
仅允许小写字母

假设web应用程序位于
/opt/myapp
中。如何在nginx中配置它

我试过以下方法,但都不管用

location ~ /sites/[a-z]+ {
   alias /opt/myapp;
   index index.html index.htm; 
}
输入
http://localhost/sites/abc/
,已禁用
403

输入
http://localhost/sites/abc/index.html
,仍然
403禁止
并且URL自动更改为
http://localhost/sites/abc/index.html/

对于
location~/sites/[a-z]+/{}

我试过了

location ~ /sites/[a-z]+ {
   alias /opt/myapp/;
   index index.html index.htm; 
}

输入
http://localhost/sites/abc
,URL重定向到
http://localhost/sites/abc/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/

正则表达式中的
别名
指令
位置
必须构成文件的完整路径

例如:

location ~ ^/sites/[a-z]+(/.*)?$ {
    alias /opt/myapp$1;
    index index.html index.htm; 
}
有关详细信息,请参阅