Rabi Siddique
304 words
2 minutes
The First time I saw use of NGINX

Fraz and I have been working together to create an end-to-end testing framework for decentralized applications (DApps). We successfully completed the framework, and our next challenge was to set up Continuous Integration (CI) for the project.

Challenge in CI Environment#

In the CI process, we encountered an issue related to the interaction between our Docker containers. Our setup involves spinning up a Docker container to simulate a local blockchain. On my local machine, I could easily make requests to the RPC node using localhost:PORT because everything ran on the same host. However, this approach didn’t work in the CI environment, where both the DApp and the local blockchain were running in separate Docker containers.

The problem arose because, in the CI environment, using localhost:PORT within one container (such as the DApp container) would only refer to the container itself, not the local blockchain container. Previously, on my local machine, I only needed to start the local blockchain container with Docker and access it via localhost, as the DApp ran directly on the machine, not inside a container. But now, with both components running in isolated containers, the direct localhost reference no longer worked.

Solution with Nginx Reverse Proxy#

Fraz used Nginx as a reverse proxy to resolve this issue. We implemented Nginx within the DApp container to route requests correctly. The setup was as follows:

  • Nginx was configured inside the DApp container.
  • Nginx was set up to listen for requests on localhost:PORT.
  • When a request was made to localhost:PORT, Nginx routed it to the appropriate container hosting the local blockchain by referencing it with the container name and the correct port (containerName:Port).

This approach allowed us to effectively bridge the gap between the containers and ensured that our CI process could make the necessary RPC calls without issues.

The code for Nginx configuration over here. Also setting up Nginx in the Dockerfile over here.

The First time I saw use of NGINX
https://rabisiddique.com/posts/first-use-of-nginx/
Author
Rabi Siddique
Published at
2024-08-17