【问题标题】:nginx rewrite not getting the entire urlnginx重写没有得到整个url
【发布时间】:2021-02-07 01:01:41
【问题描述】:

我正在尝试为以下情况实施 nginx 重写规则:请求

/config-manager/getConfig?applicationId=tweetcasterandV2.xml 应该被重定向到

/myPath/tweetcasterandV2.xml

我已经为我的服务器设置了 rewrite_log,创建了以下规则:

    location /config-manager {
      rewrite ^/config-manager/getConfig?applicationId=(.*)$  /myPath/$1  last;
    }

    location /myPath
    {
      root   /usr/share/nginx/html/myPath;
      index  index.html index.htm;
    }

但是当我发出请求时,我从服务器收到 404 Not Found 错误。错误日志包含以下内容:

root@60ade49e127b:/var/log/nginx# cat host.error.log
2020/10/24 00:20:58 [notice] 15#15: *1 "^/config-manager/getConfig?applicationId=(.*)$" does not match "/config-manager/getConfig", client: 172.17.0.1, server: localhost, request: "GET /config-manager/getConfig?applicationId=tweetcasterandV2.xml HTTP/1.1", host: "localhost:8080"
2020/10/24 00:20:58 [error] 15#15: *1 open() "/etc/nginx/html/config-manager/getConfig" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /config-manager/getConfig?applicationId=tweetcasterandV2.xml HTTP/1.1", host: "localhost:8080"
root@60ade49e127b:/var/log/nginx#

就像 rewrite 只是获取部分字符串并且无法匹配?我已经看过应该在哪里工作的教程。我需要为 nginx 设置一个特殊的参数来传递整个 URL 来重写吗?

谢谢。

【问题讨论】:

标签: nginx redirect url-rewriting


【解决方案1】:

查询字符串不是使用locationrewrite 指令测试的主题,它们使用不包含查询字符串的规范化URI。但是你可以做类似的事情

location /config-manager {
    rewrite ^ /myPath/$arg_applicationId last;
}

你也可以看看this的回答。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-05
    • 1970-01-01
    • 1970-01-01
    • 2019-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多