【问题标题】:nginx ignoring location with hyphensnginx忽略带有连字符的位置
【发布时间】:2012-07-14 04:45:11
【问题描述】:

我在使用 nginx“位置”指令和正则表达式时遇到问题。

我想让一个位置与以“/user-profile”开头的 url 匹配。

问题是 nginx 不匹配,但是如果我更改配置并尝试使用 userprofile(即没有连字符),它就像一个魅力。

我认为存在与正则表达式相关的问题,但无法解决。

我目前的配置是:

location ^~ /user-profile {
    proxy_pass http://remotesites;
}

我也尝试过:

location ^~ /user\-profile {
    proxy_pass http://remotesites;
}

感谢您能给我的任何帮助。

谢谢!

【问题讨论】:

  • location ^~ /user-profile 本身工作正常,您的问题是由您的 nginx 配置的其他部分或上游引起的。

标签: nginx


【解决方案1】:

如果您的位置在 Nginx 中没有按预期工作,请记住一件事,因为我花了很长时间才发现:

location /fred-plus {
   root /var/me
}

/fred 将被追加成为 ... /var/me/fred-plus

但是……

location /fred-plus {
    alias /var/me
}

/fred-plus 将被替换为 ... /var/me

刚从 Apache 大陆回来,花了一段时间整理一下。

我已经包含了连字符,因为在我的情况下,红鲱鱼不是问题。

【讨论】:

    【解决方案2】:

    我认为你正在寻找的是

    location ~ ^/user-profile {
        proxy_pass http://remotesites;
    }
    

    【讨论】:

      【解决方案3】:

      试试

      location ^~ "/user-profile" {
      proxy_pass http://remotesites;
      }
      

      【讨论】:

      • 这确实为我节省了无数小时。谢谢!
      猜你喜欢
      • 1970-01-01
      • 2012-03-27
      • 2021-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-19
      • 1970-01-01
      相关资源
      最近更新 更多