Nginx proxy pass for ingress and egress

Viewed 220

I would like to forward traffic using (reverse) proxy for both ingress and egress while manipulating the request and response URI's.

The scenario is this:

Ingress Request from the internet (with request uri of "/test/") enters an ec2 instance on port 8888, it then goes into a Nginx docker container that listens on this port and proxy pass it to a second docker container while 'replacing' the request uri to be "/" on port 12345 (then inside the container forward it onto port 8787 to a web application).

Egress The response that comes back from the second docker container to the Nginx container has to be "rebuild" again to the original uri ("/test/") and sent back as a response to the original client.

I think I got the ingress part by configuring the Nginx like this:

server {
    listen 8888;
    server_name 172.17.0.1;
    location / {
        proxy_pass "http://172.17.0.1:12345";
    }
}

but it seems not quite right as I thought it should be using the Nginx itself (172.17.0.3) as the "server_name" and the web application (172.17.0.2) as the upstream, but that didnt work (502 error).

I'm attaching an image for this scenario, Thanks. enter image description here

1 Answers

You can run both NGINX and Web App docker containers on the same network by creating a docker network and specifying the network while running the containers with the --network flag. With this setup, you wouldn't have to bind the host port (12345) while running the Web App and it would be accessible from the Nginx container on <webapp_container_name>:8787. So you can specify this in proxy pass - http://<webapp_container_name>:8787

Related