0

I have the following task: I need to use Google Chrome browser to navigate to: https://mytestserver.com/users/list

and this should be redirected to my local Java server that listens to Http requests on port 8080.

I'm running on Mac OSX, to achieve that I did the following:

  1. Added 127.0.0.1 mytestserver.com to /etc/host file.
  2. Installed Nginx server on Docker container with the following config:
events {
        worker_connections      1024;
}

http {
    server {
      listen                        443 ssl;
      server_name                   mytestserver.com;
      ssl_certificate               /etc/nginx/certs/star_com.crt;
      ssl_certificate_key           /etc/nginx/certs/star_com.key;
      ssl_protocols                 TLSv1 TLSv1.1 TLSv1.2;
      ssl_ciphers                   HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;

        proxy_set_header            X-Forwarded-Proto $scheme;

        location / {
            proxy_pass http://127.0.0.1:8080/;
        }
    }
}

Then I run my local application server and listen to incoming Http requests on 8080, and finally I try to run https://mytestserver.com/users/list and I'm getting 502 error. In the Nginx logs I can see this error:

2021/07/06 20:37:47 [error] 23#23: *3 connect() failed (111: Connection refused) 
while connecting to upstream, client: 172.17.0.1, server: mytestserver.com, request: 
"GET /users/list HTTP/1.1", upstream: "http://127.0.0.1:8080/users/list", host: "mytestserver.com"

What am I missing here?

Shvalb
  • 1,835
  • 2
  • 30
  • 60
  • From inside the Docker container, `127.0.0.1` is the same Docker container, not your host machine which is presumably where your app server is running? – Don't Panic Jul 07 '21 at 12:43
  • Good point! so how can I configure it redirect it to localhost outside the container? – Shvalb Jul 07 '21 at 13:51
  • I've never tried that, but there are plenty of questions here about it, eg https://stackoverflow.com/questions/31324981/how-to-access-host-port-from-docker-container. Not sure if it is easier, but if you can put your app server in another Docker container instead of on your host, you could then just use the name of the container. – Don't Panic Jul 07 '21 at 14:22

1 Answers1

0

What worked for me was setting host.docker.internal as the address for the host container.

Shvalb
  • 1,835
  • 2
  • 30
  • 60