Comments (20)
Kong is not designed to work with internal redirects, so the usage is not recommended. Would you share the use case so we can help you find an alternative solution?
our tech team plans to replace nginx with kong. In the previous nginx, internal redirection was configured for short link services. The purpose of using internal redirection is to protect the real resource path of the backend, can Kong support this internal redirects feature, otherwise we won't be able to switch from nginx to Kong
This can be achieved in more than 1 way.
- If you do not need redirected requests to go through a different set of plugins, you could use
kong.service.set_target
; - Or you could use a reverse proxy. Either with another Nginx or a separate route of the same Kong instance should work;
- Or you could customize the rewrite phase handler, to rewrite the URL before Kong's router can see it. This can be done with a global plugin or a custom Nginx template.
from kong.
@chronolaw Could you please take a look as I'm not familiar with router.
from kong.
Kong is not designed to work with internal redirects, so the usage is not recommended.
Would you share the use case so we can help you find an alternative solution?
from kong.
Kong is not designed to work with internal redirects, so the usage is not recommended. Would you share the use case so we can help you find an alternative solution?
our tech team plans to replace nginx with kong. In the previous nginx, internal redirection was configured for short link services. The purpose of using internal redirection is to protect the real resource path of the backend, can Kong support this internal redirects feature, otherwise we won't be able to switch from nginx to Kong
from kong.
Kong is not designed to work with internal redirects, so the usage is not recommended. Would you share the use case so we can help you find an alternative solution?
our tech team plans to replace nginx with kong. In the previous nginx, internal redirection was configured for short link services. The purpose of using internal redirection is to protect the real resource path of the backend, can Kong support this internal redirects feature, otherwise we won't be able to switch from nginx to Kong
This can be achieved in more than 1 way.
- If you do not need redirected requests to go through a different set of plugins, you could use
kong.service.set_target
;- Or you could use a reverse proxy. Either with another Nginx or a separate route of the same Kong instance should work;
- Or you could customize the rewrite phase handler, to rewrite the URL before Kong's router can see it. This can be done with a global plugin or a custom Nginx template.
my solution is similar to the third way,I modify the kong source code ,kong/router/atc.lua ,the problem solved, please help me check if the following solution is correct ???
function _M:exec(ctx)
local req_uri = ctx and ctx.request_uri or var.request_uri
if req_uri ~= var.uri then
req_uri = var.uri
end
... ...
from kong.
Kong is not designed to work with internal redirects, so the usage is not recommended. Would you share the use case so we can help you find an alternative solution?
our tech team plans to replace nginx with kong. In the previous nginx, internal redirection was configured for short link services. The purpose of using internal redirection is to protect the real resource path of the backend, can Kong support this internal redirects feature, otherwise we won't be able to switch from nginx to Kong
This can be achieved in more than 1 way.
- If you do not need redirected requests to go through a different set of plugins, you could use
kong.service.set_target
;- Or you could use a reverse proxy. Either with another Nginx or a separate route of the same Kong instance should work;
- Or you could customize the rewrite phase handler, to rewrite the URL before Kong's router can see it. This can be done with a global plugin or a custom Nginx template.
my solution is similar to the third way,I modify the kong source code ,kong/router/atc.lua ,the problem solved, please help me check if the following solution is correct ???
function _M:exec(ctx) local req_uri = ctx and ctx.request_uri or var.request_uri if req_uri ~= var.uri then req_uri = var.uri end ... ...
It looks like you are directly modifying ngx.var.uri. You should modify the URI with https://github.com/openresty/lua-nginx-module#ngxreqset_uri.
And this does not seem the right way. except for atc.lua, there's another flavor of router implemented with tradtional.lua.
from kong.
Kong is not designed to work with internal redirects, so the usage is not recommended. Would you share the use case so we can help you find an alternative solution?
our tech team plans to replace nginx with kong. In the previous nginx, internal redirection was configured for short link services. The purpose of using internal redirection is to protect the real resource path of the backend, can Kong support this internal redirects feature, otherwise we won't be able to switch from nginx to Kong
This can be achieved in more than 1 way.
- If you do not need redirected requests to go through a different set of plugins, you could use
kong.service.set_target
;- Or you could use a reverse proxy. Either with another Nginx or a separate route of the same Kong instance should work;
- Or you could customize the rewrite phase handler, to rewrite the URL before Kong's router can see it. This can be done with a global plugin or a custom Nginx template.
my solution is similar to the third way,I modify the kong source code ,kong/router/atc.lua ,the problem solved, please help me check if the following solution is correct ???
function _M:exec(ctx) local req_uri = ctx and ctx.request_uri or var.request_uri if req_uri ~= var.uri then req_uri = var.uri end ... ...It looks like you are directly modifying ngx.var.uri. You should modify the URI with https://github.com/openresty/lua-nginx-module#ngxreqset_uri. And this does not seem the right way. except for atc.lua, there's another flavor of router implemented with tradtional.lua.
I'm not directly modifying ngx.var.uri ,I just get the real internal redirection url (ngx.var.uri) and modify kong req_uri , refer to your suggestion, i will try to write a global plugin to modify kong req_uri , thank you.
from kong.
Glad to know it helps. Closing the ticket. Please feel free to reopen if you have further concerns.
from kong.
Glad to know it helps. Closing the ticket. Please feel free to reopen if you have further concerns.
i need redirected requests to go through a different set of plugins ,so i try the third way you suggest,but it still cannot solve the problem
function InternalRedirectionHandler:rewrite(conf)
local uri = ngx.var.uri
local request_uri = ngx.var.request_uri
local path = string.match(request_uri, "^([^?]+)")
if path and path ~= uri then
ngx.req.set_uri(uri)
end
end
because Kong's router read ngx.var.request_uri, we cannot modified it by ngx.req.set_uri(), it is read-only,
Kong's router(kong/router/atc.lua) can read ngx.var.uri(when kong redirect occurs ,ngx.var.uri is the right path) ,not ngx.var.request_uri?
from kong.
@kanbo The 3rd method I proposed is kind of a hack and sorry that does not work. I guess we need to take the 2nd method.
from kong.
@kanbo The 3rd method I proposed is kind of a hack and sorry that does not work. I guess we need to take the 2nd method.
This way requires additional deployment, which is not what we want
from kong.
@kanbo The 3rd method I proposed is kind of a hack and sorry that does not work. I guess we need to take the 2nd method.
This way requires additional deployment, which is not what we want
Maybe have a try with another route with the same Kong instance?
from kong.
@kanbo The 3rd method I proposed is kind of a hack and sorry that does not work. I guess we need to take the 2nd method.
This way requires additional deployment, which is not what we want
Maybe have a try with another route with the same Kong instance?
another route ?, i do not know how to config and test , please explain in detail
from kong.
@kanbo Add a route to Kong, with its upstream set to the redirection target, so basically use Kong itself as that Nginx to do the redirection.
from kong.
@kanbo Add a route to Kong, with its upstream set to the redirection target, so basically use Kong itself as that Nginx to do the redirection.
so the complete request order is: nginx ->target(occur redirect) ->kong ->redirect target ?
from kong.
@kanbo Add a route to Kong, with its upstream set to the redirection target, so basically use Kong itself as that Nginx to do the redirection.
so the complete request order is: nginx ->target(occur redirect) ->kong ->redirect target ?
kong->kong->redirect target
from kong.
@StarlightIbuki kong can not get real redirect path, it only read ngx.var.request_ uri, so i think this way(kong->kong->redirect target) doesn't work
from kong.
@StarlightIbuki kong can not get real redirect path, it only read ngx.var.request_ uri, so i think this way(kong->kong->redirect target) doesn't work
What I mean is to set the upstream of a route to another, say you're deploying the site on port 80:
route1: /to_be_redirected - > localhost:80/redirect_target_path
route2: /redirect_target_path->the real upstream
If we want to redirect dynamically, we can write a custom plugin for route1 to set the target
from kong.
@StarlightIbuki kong can not get real redirect path, it only read ngx.var.request_ uri, so i think this way(kong->kong->redirect target) doesn't work
What I mean is to set the upstream of a route to another, say you're deploying the site on port 80: route1: /to_be_redirected - > localhost:80/redirect_target_path route2: /redirect_target_path->the real upstream
If we want to redirect dynamically, we can write a custom plugin for route1 to set the target
this is the first method you suggested (kong.service.set_target) , but i need redirected requests to go through a different set of plugins
from kong.
@StarlightIbuki kong can not get real redirect path, it only read ngx.var.request_ uri, so i think this way(kong->kong->redirect target) doesn't work
What I mean is to set the upstream of a route to another, say you're deploying the site on port 80: route1: /to_be_redirected - > localhost:80/redirect_target_path route2: /redirect_target_path->the real upstream
If we want to redirect dynamically, we can write a custom plugin for route1 to set the target
this is the first method you suggested (kong.service.set_target) , but i need redirected requests to go through a different set of plugins
It's slightly different. The request will then be handled by Kong again, and thus it will go through the plugin set bound to the second route.
from kong.
Related Issues (20)
- OTEL plugin ignores configured header type for incoming requests HOT 2
- Memory usage of kong with DBless more keeps increasing. HOT 3
- Dev Portal: selection of Category Filter is not intuitive HOT 1
- `kong_request_latency_ms` should follow the service or route life cycle
- Kong KIC fails when rate-limiting plugin config.policy is set to cluster HOT 3
- Kong breaks cert-manager certificate creation HOT 12
- db_import with keyauth_credentials fails on re-run HOT 9
- Kong returns 503 error to api-client due to failure in DNS resolution of upstream service HOT 7
- Kong Manager in Kong OSS HOT 1
- REF: A question with cti. Yugabyte issue #12314 HOT 1
- Opentelemetry - span name is Kong HOT 3
- Nil entity returned when using dao select statement on Kong 3.3 Postgres
- Not being able to filter access logs since 3.5.0.2 HOT 6
- 100% CPU usage and keep posting event 'reset_instances' to go plugin server HOT 1
- 100% CPU usage and keep posting event 'reset_instances' to go plugin server HOT 11
- failed to connect: ssl set client certificate failed
- kong can't start by `xpcall` HOT 3
- large discrepancy between request_time and upstream_response_time HOT 4
- "declarative_config.lua:654: table index is nil" with custom lua plugin (via configmap)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kong.