Configuring the reverse proxy
Configure nginx on the host using the Docker gateway address and the ports exposed by each service.
This example uses nginx as the HTTP reverse proxy on the host. Start with the configuration used by the built-in Reverse Proxy service.
Docker Swarm uses an overlay network. Services on that network are not accessible at localhost. Use ip addr to find the address used to access the stack.
Example output:
...
5: docker_gwbridge: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:98:4e:fe:bc brd ff:ff:ff:ff:ff:ff
inet 172.21.0.1/16 brd 172.21.255.255 scope global docker_gwbridge
valid_lft forever preferred_lft forever
inet6 fe80::42:98ff:fe4e:febc/64 scope link
valid_lft forever preferred_lft forever
...
Use the address assigned to docker_gwbridge when configuring the reverse proxy. The address given in this example is 127.21.0.1.
In nginx.conf, replace the built-in Reverse Proxy destination addresses. For example, replace http://gateway with http://ip_address_docker_gwbridge:the_port_where_the_service_was_exposed. Update the other location blocks in the same way.