1

Here is the configuration for my reverse proxy server:

server {
  listen 8085 ssl;
  server_name  localhost;
  location / {
    proxy_pass http://192.168.85.56:8080;
  }
}

For an incoming path, e.g.: https://localhost:8085/path1/1/path2/, I want to remove the /1/, so the resulting path will be https://localhost:8085/path1/path2/.

One constraint is that path1 can change to any string.

Also, matching on any number instead of just 1 is also a valid solution.

How can this be done?

Edit: My problem is very similar to this one, except that I have a string, path1, that can vary.

toerq
  • 11
  • 2

1 Answers1

0

Use a rewrite...break inside the location block.

For example:

location / {
    rewrite ^(.*)/[0-9]+/(.*)$ $1/$2 break;
    proxy_pass http://192.168.85.56:8080;
}

See this document for details.

Richard Smith
  • 11,859
  • 2
  • 18
  • 26
  • It worked with one caveat. The server I am running is a Spark history server and with this solution, I need to click the links to each "application history data" twice. Once a link has been clicked, it does not need to be clicked twice again. I suppose the `/1/` tells the server to load the history data into memory. Is there any workaround for this? – toerq Nov 21 '19 at 08:00