Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

506
Vistas
Cannot get headers in flask app through nginx-gunicorn

I' m trying to get real ip addresses of users who visit the site. For that, I'd like to add custom authorization for API service. Using headers for both cases seems like a good idea.

The problem is that I cannot get custom headers in my flask app that is served by nginx and gunicorn web-servers. Getting 'remote_addr' headers returns only 127.0.0.1 IP address despite the fact I post from outer network, not from localhost.

Here are my configuration files:

part of nginx config //1.14.2

location / {
        # forward application requests to the gunicorn server
        proxy_read_timeout 30s;
        proxy_send_timeout 30s;
        proxy_connect_timeout 30s;
        proxy_pass http://127.0.0.1:5000;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        add_header CLIENT-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

part of gunicorn config //20.0.4

[program:wapp]
command=/home/deeslo/processor/venv/bin/gunicorn -b localhost:5000 -w 4 microservice:app
directory=/home/deeslo/processor
user=deeslo
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true

When I check headers, I don't see there neither X-Real-IP/CLIENT-IP from nginx nor other custom headers that I sent in flask make response headers.

What did I miss? Could not solve it yet.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Oh, that was totally my fault.

The problem was I was debugging the application in my IDE where the application was running through embedded web-server, not nginx.

The solution above works perfect, I can get User IP address in flask app with:

request.header['X-Real-IP']

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda