nginx位置模式匹配不起作用

时间:2015-04-15 22:29:39

标签: nginx configuration

我正在尝试更改nginx配置,以便所有包含样式的网址都被剥离,以便只有URL的一部分包括'样式'被发送到下游应用程序。

请求包含网址" http://def.testing.com/abc/styles/fonts/Avenir-Roman/font.css"匹配第一个模式,但我希望它匹配第二个模式,因为第二个模式中有reg-ex。

有人可以向我解释这里发生了什么吗?

location /abc/ {
    try_files $uri/index.html $uri @app;
}

location /abc.*/styles/ {
    rewrite ^/abc.*/(styles.*) /$1 break;
    try_files $uri/index.html $uri @app;
}

URL:

http://10.10.10.10/abc/styles/fonts/Avenir-Roman/font.css

1 个答案:

答案 0 :(得分:1)

您是否忘记在正则表达式中添加波形符?

location ~ ^/abc.*/styles/ {
    rewrite ^/abc.*/(styles.*) /$1 break;
    try_files $uri/index.html $uri @app;
}
相关问题