Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to proxy + rewrite in a single route #1462

Open
RangerRick opened this issue Oct 16, 2024 · 1 comment
Open

unable to proxy + rewrite in a single route #1462

RangerRick opened this issue Oct 16, 2024 · 1 comment
Milestone

Comments

@RangerRick
Copy link

RangerRick commented Oct 16, 2024

I would like to attach a sub-url to my unit config so that a particular URL proxies, but also rewrites the path passed to the proxy by stripping the sub-url.

For example, a request to /s3/mybucket/blah/foo would proxy to http://1.2.3.4:8333/mybucket/blah/foo, stripping the /s3 from the beginning the path.

I've attempted a bunch of different variations and I can't seem to find a way to make it work, although the documentation says "All route step actions support the rewrite option". Is this just not supported, or am I just doing something wrong?

Here's the config:

{
  "listeners": {
    "0.0.0.0:8080": {
      "pass": "routes/main"
    }
  },
  "routes": {
    "main": [
      {
        "match": {
          "uri": "/static/*"
        },
        "action": {
          "share": "/opt/myapp${uri}"
        }
      },
      {
        "match": {
          "uri": "~^/?s3/(.*)$"
        },
        "action": {
          "rewrite": "/$1",
          "proxy": "http://<ip-addr>:8333/"
        }
      },
      {
        "action": {
          "pass": "applications/myapp"
        }
      }
    ]
  },
  "applications": {
    "myapp": {
      "type": "python 3",
      "path": "/opt/myapp/",
      "module": "myapp.wsgi",
      "home": "/opt/myapp/venv",
      "processes": {
        "max": 4,
        "spare": 1,
        "idle_timeout": 120
      }
    }
  },
  "access_log": "/dev/stdout"
}
@hongzhidao
Copy link
Contributor

Hi,
Currently, it's not supported yet. But we've discussed it and will release it in 1.34 as the next version.
https://github.com/nginx/unit/issues/544
Btw, it will be different from nginx's way. Nginx provides a number-format variable, but we think it's better to support only captured name variables in Unit.

@callahad callahad added this to the 1.34 milestone Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants