Nginx as Proxy in Azure VM running Ubuntu cannot route in Swarm Mode to backend app

I am struggling to get a simple nginx proxy working in Azure VMs ( 3 VMs:1 master+ 2 workers , Ubuntu 16.04, Standard B2s (2 vcpus, 4 GB memory) at work. I have the services running in the swarm. Master1, Worker1, Worker2. The proxy and backend app are running on worker 2.

Kindly advice if I am doing anything wrong or if there is something specific I need to do for it to run in a VM in Azure.

  1. when I hit the proxy endpoint port 8080 on worker 1 ip in the browser, I get “Site cant be reached”. I thought it would route the request to worker2?

  2. when I hit the proxy endpoint port 8080 on worker 2 in the browser, I get the default nginx page as expected. However, When I hit the proxy endpoint port 80 on worker 2 in the browse , I was expecting to have the called routed to the whoami service. Instead I get

image.png

Below are the steps I have done. I am still not able to connect to the backend app.

Kindly advice.

First Service (nginx) : proxy

=======================

docker service create \

–detach=false \

–name proxy \

–constraint node.role==worker \

–replicas 1 \

–publish 8080:80 \

nginx:alpine

Add Overlay Network called app

==============================

docker network create \

–driver overlay \

app

Update proxy service and Attach the proxy to the app overlay network

====================================================================

docker service update \

–detach=false \

–network-add app \

proxy

Create backend service and attach to the app network created earlier: whoami

=============================================================================

docker service create \

–detach=false \

–name whoami \

–constraint node.role==worker \

–replicas 2 \

–network app \

emilevauge/whoami

Create a dockerfile that links the proxy and the whoami service

===============================================================

  1. backend.conf

upstream backend {

server whoami;

}

server {

listen 80;

location / {

proxy_pass [http://backend](http://backend/);

proxy_connect_timeout 5s;

proxy_read_timeout 5s;

}

}

  1. Dockerfile

FROM nginx:alpine

RUN rm /etc/nginx/conf.d/*

COPY backend.conf /etc/nginx/conf.d/

Create the new proxy image

======================

docker build -t nginx-2 .

docker service update \

–detach=false \

–image nginx-2 proxy