I would like to do the following in my NGINX configuration: I want to proxy pass the path and query parameters but not include the first path parameter (path1).
Request URL
https://my-domain.com/path1/path2?query1=some-query
I want this to proxy_pass to
http://localhost:8000/path2?query1=some-query
I have tried with the following location block
location /path1/path2/ {
proxy_pass http://localhost:8000$request_uri;
proxy_http_version 1.1;
}
However, this does not go to the correct endpoint because I think it includes the path1
parameter too. I have several different path2
routes and so I want to be able to catch and redirect them all easily - without having to manually define each one like this:
location /path1/path2a/ {
proxy_pass http://localhost:8000/path2a?query1=some-query;
proxy_http_version 1.1;
}
location /path1/path2b/ {
proxy_pass http://localhost:8000/path2b?query1=some-query;
proxy_http_version 1.1;
}
location /path1/path2c/ {
proxy_pass http://localhost:8000/path2c?query1=some-query;
proxy_http_version 1.1;
}
ADDITIONAL EDIT:
I also cannot simply do
location /path1/ {
proxy_pass http://localhost:8000/;
proxy_http_version 1.1;
}
because I already have the location /path1/
block that gets upgraded to a WebSocket connection at a different endpoint:
location /path1/ {
proxy_pass http://localhost:9000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
I have searched a lot online but cannot find a configuration that works for my specific scenario.