简体   繁体   English

nginx 重写没有得到整个 url

[英]nginx rewrite not getting the entire url

I'm trying to implement nginx rewrite rules for the following situtation: Request我正在尝试为以下情况实施 nginx 重写规则:请求

/config-manager/getConfig?applicationId=tweetcasterandV2.xml should be redirected to /config-manager/getConfig?applicationId=tweetcasterandV2.xml应该重定向到

/myPath/tweetcasterandV2.xml

I've set rewrite_log on for my server, created following rules:我为我的服务器设置了 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;
    }

but when I do the request, I get 404 Not Found error from server.但是当我执行请求时,我从服务器收到 404 Not Found 错误。 The error log contains the following:错误日志包含以下内容:

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#

It's like rewrite is only getting a partial string and failing to match?好像 rewrite 只是获取了部分字符串而无法匹配? I've seen tutorial where this is supposed to work.我看过教程,它应该可以工作。 Is there a special parameter I need to set for nginx to pass the entire URL to rewrite?是否需要为 nginx 设置特殊参数以传递整个 URL 进行重写?

Thanks.谢谢。

Query string is not a subject to test with location or rewrite directives, they work with the normalized URI which doesn't include a query string.查询字符串不是使用locationrewrite指令进行测试的主题,它们使用不包含查询字符串的规范化 URI。 However you can do something like但是你可以做类似的事情

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

You can also take a look at this answer.你也可以看看这个答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM