When I used nginx in docker swarm mode I always got the IP of the nginx container instead of the real public IP of the user.
my stack:
version: '3.9'
services:
nginx_proxy:
image: 'nginx'
ports:
- '80:80'
- '443:443'
after some searches on the internet if found a solution but it causes another problem the solution is to change the ports to:
version: '3.9'
services:
nginx_proxy:
image: 'nginx'
ports:
- mode: host
protocol: tcp
published: 443
target: 443
- mode: host
protocol: tcp
published: 80
target: 80
After this change the nginx will get the real public IP but only one replica will work you can not run more than one even if you are specifying in your stack on one will work and it will show:
ID NAME MODE REPLICAS IMAGE
ga5w8633lm8q nginx-proxy_nginx replicated 1/5 nginx:latest