Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x-forwarded-for docker-compose network #1287

Closed
La-source opened this issue Jun 8, 2019 · 4 comments
Closed

x-forwarded-for docker-compose network #1287

La-source opened this issue Jun 8, 2019 · 4 comments

Comments

@La-source
Copy link

Hello,

By setting nginx-proxy with docker-compose and an external network the remote ip address is the internal IP address and not the client IP address.

version: '2'

services:
  app:
    image: node:12-alpine
    restart: always
    command: sh -c "npm install && npm start"
    working_dir: /app
    expose:
      - 3000
    volumes:
      - ./dist:/app
    environment:
      - VIRTUAL_HOST=domain.com
      - VIRTUAL_PORT=3000
  proxy:
    image: jwilder/nginx-proxy
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./vhost.d:/etc/nginx/vhost.d
      - ./certs:/etc/nginx/certs:ro
      - ./html:/usr/share/nginx/html
      - /var/run/docker.sock:/tmp/docker.sock:ro
    environment:
      - ENABLE_IPV6=true
    logging:
      driver: "none"

networks:
  default:
    external:
      name: nginx-proxy

Result:

'x-real-ip': '172.23.0.1',
'x-forwarded-for': '172.23.0.1',
'x-forwarded-proto': 'https',
'x-forwarded-ssl': 'on',
'x-forwarded-port': '443',
@La-source
Copy link
Author

Hello,

After a lot of research I noticed that it was a real problem with docker and that help on this subject is quite poor.

Concretely, the solution that worked for me is to add network_mode: 'host' in nginx-proxy to get the correct ip address.

In the case of a docker-dial version 3 it is necessary to follow this syntax: moby/moby#25526 (comment)

I think an addition to the documentation will not be too much.

@Munzy
Copy link

Munzy commented Nov 3, 2019

Can you show an example of your config?

@windmemory
Copy link

This issue is related to docker/roadmap#157

I am also experiencing this problem, and seems like the network_mode: host is the only solution now.

@rjhancock
Copy link

network_mode: host only works on Linux and is not suitable for any other platform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants