Obtaining Client's Public IP Address in Flask Docker Container on Railway.app
I have a Docker container on Railway.app with a Flask app running on Gunicorn. When I try to view the client's IP address, it provides a local IP rather than a public one. What could be the reason, and how can I solve it? Thank you.
gunicorn --workers=1 --bind 0.0.0.0:5001 --preload 'wsgi:create_app()' --timeout 90
Solution:Jump to solution
Railway will foward a header called "X-Envoy-External-Address". you've to tell flask to trust that.
example:
```py
if request.headers.get("X-Envoy-External-Address"):...
14 Replies
As I understand there is a way of obtaining it, but railway really does not want you to
Solution
Railway will foward a header called "X-Envoy-External-Address". you've to tell flask to trust that.
example:
oh I misunderstood, thought you meant the IP of your running service, my bad
Thanks let me check
I'd like to note thalles's solution is only applicable if railway is the only proxy your app sits behind, if you where for example running your app behind cloudflare's proxy you would want to read the
CF-Connecting-IP
header insteadNo I am exposing directly the railway ip
explain
also, flask has a trust proxy feature, but i don't know it's behavior when a client tries to spoof the
x-forwaded-for
header.
https://flask.palletsprojects.com/en/latest/deploying/proxy_fix/
i would go with the X-Envoy-External-Address
if you just want something to work for now.it' works perfertly thanks a lot @ThallesComH
explain please, if I understand you correctly, you may be doing something wrong
I deployed a docker on railway by github, and in settings -> networking there is an url, i am using that url from the front to call the api hosted.
okay, dont know why you mentioned the "railway ip" then
I wanted to say the Railway URL.
gotcha