Reputation: 109
I'm trying to implement nginx rewrite rules for the following situtation : Request
/config-manager/getConfig?applicationId=tweetcasterandV2.xml
should be redirected to
/myPath/tweetcasterandV2.xml
I've set rewrite_log on for my server, created following rules:
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. 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? 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?
Thanks.
Upvotes: 0
Views: 527
Reputation: 15537
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. However you can do something like
location /config-manager {
rewrite ^ /myPath/$arg_applicationId last;
}
You can also take a look at this answer.
Upvotes: 0