Configuring PAS to Route Traffic to Apps on Custom Ports

Page last updated:

This topic describes how to configure Pivotal Application Service (PAS) to route traffic to your apps listening on custom ports.

Overview

By default, apps only receive requests on port 8080 for both HTTP and TCP routing, and so must be configured, or hardcoded, to listen on this port. Configuring custom app ports allows developers to bring workloads onto PAS that listen on ports other than 8080. Some example use cases are:

  • Serving web client requests on one port and offering stats/debug on another

  • Using TCP protocols that require multiple ports

  • Running Docker images on PAS

The 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.

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.

Port Type Description Network Hop
Route port The port a client sends a request to Client to load balancer, load balancer to Gorouter
Back end port The port on the VM where an app container is hosted, which is unique to the container Gorouter to Diego Cell
App port The port on the container; this must match a port the app is configured to listen on Diego Cell to app container

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.

Traffic-flow-diagram

Prerequisites

Before following the procedure to configure routing to your app on custom ports, you must have:

  • An app pushed to PAS that can listen on one or more custom ports.

  • An app pushed to PAS 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 for more info). Consider an example in which you have two routes: foo.example.com and bar.example.com. In the following procedure, you use API endpoints to map these routes to your app on the ports it is listening.

Procedure

To configure your app to receive HTTP or TCP traffic on custom ports:

  1. Retrieve the GUID of your app by running:

    cf app APP-NAME --guid
    

    Where APP-NAME is the name of your app.

  2. Configure PAS with the ports your app is listening on by running:

    cf curl /v2/apps/APP-GUID -X PUT -d '{"ports": [PORT1, PORT2, PORT3...]}' 
    

    Where:

    • 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.
  3. Retrieve the GUID of the route to which clients make requests, and for which PAS routes requests to the app on a custom port, by running:

    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.

  4. Update the route mapping for your app by running:

    cf curl /v2/route_mappings -X POST -d '{"app_guid": "APP-GUID", "route_guid": "ROUTE-GUID", "app_port": PORT1}'. 
    

    Where:

    • 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.
  5. Repeat the previous two steps for each port that you want your app to receive requests on.

Additional Resources

For additional resources related to configuring custom app ports: