unable to proxy + rewrite in a single route
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"
}
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.