Configuring Services and Routes#
This section describes how to configure an upstream app with Gluu Gateway. GG uses Kong as its proxy with a very simple flow, described below. You just need to add your upstream application in kong.
Create a new Service#
First, add the Upstream Application in Kong. In Kong, the Service entity represents the
Upstream Application. Just add the Upstream Application's URL.
Servicessection, left side in the navigation menu.
+ ADD NEW SERVICEbutton.
It will open the following form.
For Example: If your upstream service URL is
http://localhost:5555, then set the URL to
http://localhost:5555and the name to
Kong also allows Services to be configured using
Port(optional). To configure the Service using this method, you just need to leave the URL field and enter values in this field one by one. The URL field is just quick and short way to configure service.
SUBMIT SERVICEat the bottom of the form
If successful, it will show it in list. Click on name of the service or pencil icon to see full details about service.
Create a new Route attached to the Service#
The second step is to create a route in the newly created Service. The Route represents the actual request to the Kong proxy endpoint to reach at Kong service.
To create a new Route, click on service name or pencil icon and it will open below view.
Routes. It will show you previously-created routes. Click on
+ ADD ROUTEbutton to add new route.
After clicking on the button, it will open the following form. The Route will also need a name, and at least one of the following fields:
Paths. Set the name to
test-service-routeand hosts to
test.com. Press enter after adding values to the hosts field.
SUBMIT ROUTEbutton at the bottom of form to create route.
If successful, it will shows it in listing in
Test the new Service and Route#
Use the following curl command which sends a request to the Kong proxy endpoint and verifies that Kong is properly forwarding request to Service. As per default, the setup Kong proxy endpoint is exposed on
Run this command on the same machine where you installed Gluu Gateway. This example uses
https://localhostbecause I am on the same machine.
curl -k -X GET \ https://localhost \ -H 'Host: test.com'
Run this command on any other machine, after exposing the proxy endpoint globally with a domain. For example: if GG is installed on
dev.gluu.orgthen request will be
curl -k -X GET \ https://dev.gluu.org \ -H 'Host: test.com'
For example, with the
/usersendpoint, add an endpoint path in URL like below example.
curl -k -X GET \ https://dev.gluu.org/users \ -H 'Host: test.com'
One important thing is here,
Host: test.com is passed in the header at the filter for the newly created route, which is configured with same host details. When the request is made, Kong matches all the requests with Kong route configurations. In the above case, it is matching
host. There are several possibilities for routing.
The route configuration is just like defining APIs in any programming language, adding HTTP Methods and Endpoint Paths. Here, Kong has more powerful tools for routing. The Route can add
Headers. For example,
- GREEN requests are valid and allowed by Kong.
- RED requests are invalid and deny by Kong.
Configure multiple Upstream Application#
Multiple upstream applications can be configured in Kong. You just need to organization and configure the routes.
For Example: we have three upstream applications http://localhost:5001, http://localhost:5002 and http://localhost:5003 then the configuration is follows:
This example uses the
PATHs field of the Route to configure and differentiate the request from other services.
http://localhost:5001, request with
Host: test.com in header.
http://localhost:5002, request with
Host: test.com and
/v2 in URL.
http://localhost:5003, request with
Host: test.com and
/v3 in URL.