I have following problem. I have a docker compose setup which spins up a frontend service using Nuxt3 and a backend API based on golang.This two containers are exposed via an Nginx reverse proxy everything works as expected but I need to retrieve the users IP adress inside my golang service. Nginx seems to forward just a docker ip with 172.x.x.x not the real users IP address.
docker-compose.yaml
version: '3'
services:
nuxt-frontend:
build:
context: ./frontend # Path to your Nuxt 3 backend code
dockerfile: Dockerfile.local
command: npm run dev
x-develop:
watch:
- action: sync
path: ./frontend
target: /app
ignore:
- node_modules/
- action: rebuild
path: package.json
mongodb:
image: mongo:latest
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: admin
volumes:
- mongodb_data:/data/db
go-backend:
build:
context: ./backend
dockerfile: Dockerfile.local
command: air
x-develop:
watch:
- action: sync
path: ./backend
target: /app
- action: rebuild
path: go.mod
depends_on:
- mongodb
nginx:
image: nginx:latest
ports:
- "80:80" # HTTP port
- "443:443" # HTTPS port
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
- ./nginx/ssl:/etc/nginx/ssl
depends_on:
- nuxt-frontend
- go-backend
volumes:
cache:
driver: local
mongodb_data:
nginx.conf
server {
listen 80;
server_name localhost;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name localhost;
ssl_certificate /etc/nginx/ssl/cert.pem;
ssl_certificate_key /etc/nginx/ssl/key.pem;
location /api {
proxy_pass http://go-backend:3001;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location / {
proxy_pass http://nuxt-frontend:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Any suggestions are highly appreciated.
Kind regards