2

I am trying to setup a docker network of two containers. One container holds a Wildfly application, and the other machine is an Nginx proxy server. The proxy server is just a placeholder for a load balancer used in a production environment. Therefore, the Nginx server simply forwards all requests to the wildfly server on :8080.

This setup works when I run the containers in the default bridge network, but I would like to use a user-defined network to mimic hostname resolution. But when I run the setup in a user-defined network, I can no longer reach the Wildfly application through the Nginx server, and I only get 504 timeout errors.

This is my nginx configuration file:

server {
    listen 80;
    return 301 https://$host$request_uri;
}

server {

    listen 443;
    server_name dev-reports.passkey.com;

    ssl_certificate           /etc/nginx/cert.crt;
    ssl_certificate_key       /etc/nginx/cert.key;

    ssl on;
    ssl_session_cache  builtin:1000  shared:SSL:10m;
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;

    access_log            /var/log/nginx/rpt.access.log;

    location / {
      sub_filter '172.18.0.2'  '127.0.0.2';
      proxy_set_header         Host $host;
      proxy_set_header         X-Real-IP $remote_addr;
      proxy_set_header         X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header         X-Forwarded-Proto $scheme;

      # Fix the “It appears that your reverse proxy set up is broken" error.
      proxy_pass          http://172.18.0.2:8080;
      proxy_connect_timeout       900;
      proxy_send_timeout          900;
      proxy_read_timeout          900;
      send_timeout                900;
    }
}

And these are the scripts I use to run the Nginx server:

IP=127.0.0.3
docker run -d --name nginx-server -v ~/path/to/logs:/var/log/nginx --network user-network -p $IP:8443:443 nginx

And the Wildfly server:

IP=127.0.0.2
docker run -d --name wildfly-app --network user-network -v $1:/mnt/share -v $1/logs:/opt/wildfly/standalone/log/ -p $IP:9990:9990 -p $IP:80:8080 -p $IP:8787:8787 -p $IP:443:8443 -p $IP:1099:1099 -p $IP:1129:1129 -p $IP:1139:1139 -p $IP:8083:8083 -p $IP:8889:8889 wildfly-app

I run sudo ifconfig lo0 alias 127.0.0.* up To open up 127.0.0.2 and 127.0.0.3

Christian Baker
  • 375
  • 2
  • 7
  • 22

0 Answers0