In this tutorial, we are going to walk through the dockerized light-proxy in light-docker. There are two docker-compose files and separate config files for Swagger 2.0 and OpenAPI 3.0 specification.
We are going to use OpenAPI 3.0 compose file, and Swagger 2.0 is very similar to the OpenAPI 3.0 one with only config file difference.
Start backend services
Before we start the proxy compose, we need to start three instances of OpenAPI proxy-backend services. The steps are described in OpenAPI proxy backend. Please follow it to start all three instances and make sure they are working individually.
Now let’s clone the light-docker repo from networknt on github.com site.
git clone https://github.com/networknt/light-docker.git
docker-compose -f docker-compose-openapi-proxy.yml up
Once the proxy server is up, you can test it with the following curl command.
If you want to run this tutorial on your computer, you have to update the proxy.yml in light-docker/light-proxy/openapi/config folder.
Here is the config file for my computer, which is named freedom. You cannot use the localhost anymore as the localhost within the docker container means the docker OS itself. Except for this change, the configuration for the dockerized light-proxy is the same as you are running the standalone light-proxy server. You need to change the hostname freedom to your computer name or your IP address. If you are using a hostname, you need to ensure that you can ping the hostname on your computer. Otherwise, it is safe to use IP address with 192.xxx.xxx.xxx or 10.xxx.xxx.xxx
---# Reverse Proxy Handler Configuration# If HTTP 2.0 protocol will be used to connect to target servershttp2Enabled:true# If TLS is enabled when connecting to the target servershttpsEnabled:true# Target URIshosts:https://freedom:8081,https://freedom:8082,https://freedom:8083# Connections per thread to the target serversconnectionsPerThread:20# Max request time in milliseconds before timeoutmaxRequestTime:1000# Rewrite Host Header with the target host and port and write X_FORWARDED_HOST with original hostrewriteHostHeader:true# Reuse XForwarded for the target XForwarded headerreuseXForwarded:false# Max Connection RetriesmaxConnectionRetries:3
Other config files
There are other config files in the config folder for the docker-compose, and you can modify them to test different behavior of the light-proxy.
For example, you can enable security, metrics, etc.