Nginx 如何代理和重写URL,如/app/(通配符)/(实际上是重写路径)

Nginx 如何代理和重写URL,如/app/(通配符)/(实际上是重写路径),nginx,nginx-location,Nginx,Nginx Location,我想重写和代理所有URL,如 http://foo.com/app/groupA/index.html http://foo.com/app/groupB/index.html 到 请注意groupA和groupB URL是如何重写到同一位置的 我已经尝试了很多方法,我认为这很可能会奏效,因为它与第三次出现/后的所有方法都匹配 location /app { rewrite (?:.*?\/){3}(.*) /$1 break; index index.html index.htm;

我想重写和代理所有URL,如

http://foo.com/app/groupA/index.html
http://foo.com/app/groupB/index.html

请注意groupA和groupB URL是如何重写到同一位置的

我已经尝试了很多方法,我认为这很可能会奏效,因为它与第三次出现
/
后的所有方法都匹配

location /app {
  rewrite (?:.*?\/){3}(.*) /$1 break;
  index index.html index.htm;
  proxy_pass http://localhost:8080;
  proxy_redirect    off;
  proxy_set_header  Host $host;  
  proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header  X-Forwarded-Ssl on;
  proxy_buffering  off; # buffering would break CouchDB's _changes feed
  proxy_read_timeout 600s;
  proxy_send_timeout 600s;
  proxy_connect_timeout 75s;
}
但在8080端口上,我没有看到其他请求。注意,我在写时确实看到请求

  location ^~ /app {
    rewrite /app/(.*) /$1 break;
    index index.html index.htm;
    proxy_pass http://localhost:8080;
    proxy_redirect    off;
    proxy_set_header  Host $host;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header  X-Forwarded-Ssl on;
    proxy_buffering  off; # buffering would break CouchDB's _changes feed
    proxy_read_timeout 600s;
    proxy_send_timeout 600s;
    proxy_connect_timeout 75s;
  }
请求在端口8080上作为

 /groupA/index.html
 /groupB/index.html

我需要弄清楚如何去掉URL中的/groupA/和/groupB/部分。注意,我实际上不知道组所在的斜线之间的字符串是什么。据我所知,它可能是/funnybunny/:P.

其中正则表达式包含大括号字符

{}
表达式应该用引号括起来

尝试:


在第一个示例中,我看到请求在端口8080上传入,尽管它们包含
/groupA/index.html
,但仍然存在相同的问题。
 /groupA/index.html
 /groupB/index.html
rewrite "(?:.*?\/){3}(.*)" /$1 break;