10

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

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

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

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

我目前的配置是:

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

我也尝试过:

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

我很感激你能给我的任何帮助。

谢谢!

4

3 回答 3

4

尝试

location ^~ "/user-profile" {
proxy_pass http://remotesites;
}
于 2018-08-15T23:19:22.777 回答
0

One thing to remember if your location is not working as expected in Nginx, as I just spent ages finding out:

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

/fred will be APPENDED to become ... /var/me/fred-plus

but ...

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

/fred-plus will REPLACED to become ... /var/me

Just spent a fair while sorting this out after coming from Apache land.

I've included the hyphen as it was the red herring that was not the problem in my case.

于 2021-12-27T08:14:00.400 回答
0

我想你正在寻找的是

location ~ ^/user-profile {
    proxy_pass http://remotesites;
}
于 2020-07-27T12:35:07.037 回答