【问题标题】:nginx location contains string + end withnginx 位置包含字符串 + 以结尾
【发布时间】:2018-10-16 15:25:12
【问题描述】:

如何在 Nginx 中匹配位置:

  • 包含 /render/framed/

  • 以 .php 结尾

我尝试location ~ /render/framed/ { 只是为了包含“/render/framed/”并且它有效。 但是找不到如何指定,必须以.php结尾

已尝试:location ~ /render/framed/+\.php$ {

有可能吗?

【问题讨论】:

  • 试试/render/framed/.*\.php而不是/render/framed/+\.php$
  • @Sergio 不幸的是无法正常工作location ~ /render/framed/.*\.php {
  • 实际上,location ~ /render/framed/.*\.php$ { 应该可以工作(注意$ 锚点)。可能,您可能需要使用双引号 location ~ "/render/framed/.*\.php$" {,但不确定。此外,请尝试将 ~ 替换为 ~* 以进行不区分大小写的匹配。
  • 是的,应该可以工作,但这不是因为它是 404 响应 error_page 404 = /url_rewriting.php;location 不适用于 404 响应。

标签: regex nginx location


【解决方案1】:

快速搜索告诉我 NGINX 使用了良好的旧 PCRE 正则表达式风格。这就是你想要的 -

Sometext /render/framed/ .php - 应该匹配

Sometext /render/framed/ .txt - 不应该匹配

那么下面的模式应该可以工作。如果没有,您能否提供一些测试字符串和所需的输出。

.*(?:\/render\/framed).*(?:.php)$

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-14
    • 2023-04-05
    • 1970-01-01
    相关资源
    最近更新 更多