Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
104 lines (76 sloc) 4.83 KB
title: Configuring CF to Route Traffic to Apps on Custom Ports
owner: Routing
This topic describes how to configure <%= vars.first_product_name %> to route traffic to your apps listening on custom ports.
## <a id="overview"></a> Overview
By default, apps only receive requests on port 8080 for both HTTP and TCP routing, and so must be configured, or hard coded, to listen on this port. Configuring custom app ports allows developers to bring workloads onto <%= vars.product_short %> that listen on ports other than 8080. Here are some example use cases:
* Serving web client requests on one port and offering stats/debug on another
* Using TCP protocols that require multiple ports
* Running Docker images on <%= vars.product_short %>
The [Procedure](#procedure) below describes how to use the `apps` and `route_mappings` Cloud Controller API endpoints to update the ports the app can receive requests on.
### <a id="flow"></a> Flow of a Request to an App
The following table describes the Network Address Translation that occurs in the data path of a client request. The procedure in this document discusses configuring _app ports_ specifically.
<th>Port Type</th>
<th>Network Hop</th>
<td>Route port</td>
<td>The port a client sends a request to</td>
<td>Client to load balancer, load balancer to Gorouter</td>
<td>Backend port</td>
<td>The port on the VM where an app container is hosted, which is unique to the container</td>
<td>Gorouter to Diego Cell</td>
<td>App port</td>
<td>The port on the container; this must match a port the app is configured to listen on</td>
<td>Diego Cell to app container</td>
The following diagram provides an example data path and Network Address Translation for TCP Routing. For HTTP Routing, the Route Port is always `80` or `443`.
## <a id="prerequisite"></a> Prerequisites
Before following the procedure to configure routing to your app on custom ports, you must have the following:
* An app pushed to <%= vars.product_short %> that can listen on one or more custom ports.
* Routes for which you want traffic forwarded to your app on custom ports.
* If your app listens on two ports and you want clients to be able to send requests to both of them, create two routes. These can be from HTTP or TCP domains (see [Routes and Domains](./deploy-apps/routes-domains.html) for more info). Consider an example in which you have two routes: `` and ``. In the following procedure, you use API endpoints to map these routes to your app on the ports it is listening.
## <a id="procedure"></a> Procedure
To configure your app to receive HTTP or TCP traffic on custom ports, do the following:
1. Retrieve the GUID of your app:
cf app APP-NAME --guid
Where `APP-NAME` is the name of your app
1. Configure <%= vars.product_short %> with the ports your app is listening on:
cf curl /v2/apps/APP-GUID -X PUT -d '{"ports": [PORT1, PORT2, PORT3...]}'
* `APP-GUID` is the GUID of your app
* `PORT1, PORT2, PORT3...` is a comma-separated list of the ports on which you want your app to receive traffic.
1. Retrieve the GUID of the route to which clients will make requests, and for which Cloud Foundry will route requests to the app on a custom port:
cf curl /v2/routes?q=host:HOST-NAME
Where `HOST-NAME` is the hostname for the route; by default this is the name of your app.
1. Update the route mapping for your app:
cf curl /v2/route_mappings -X POST -d '{"app_guid": "APP-GUID", "route_guid": "ROUTE-GUID", "app_port": PORT1}'.
* `APP-GUID` is the GUID of your app
* `ROUTE-GUID` is the GUID of the route at which the app serves.
* `PORT1` is the app port, or one of the app ports, that you added in the previous step.
1. Repeat the previous two steps for each port that you want your app to receive requests on.
## <a id="additional-resources"></a> Additional Resources
Here are additional resources related to configuring custom app ports:
* For more information about making requests to the Cloud Controller `apps` endpoint, see [Updating an App]( in the Cloud Controller API documentation.
* For more information about making requests to the Cloud Controller `route_mappings` endpoint, see [Mapping an App and a Route](
* For an example multi-port app, see the [cf-acceptance-tests]( repository.
* For a demo procedure written by an open source CF user, see ["Multiple App Ports" Demo on Cloud Foundry](
You can’t perform that action at this time.