Remote address overwritten when deploying docker images
Anonymous
TRIALOP

2 years ago

Hi, I have a docker image containing angular SPA and nginx. NGINX is configured to pass the remote addr from cloudflare, so that I can see the real ip in the nginx logs. My problem is, that docker overwrites the remote addr, so that in NGINX I'm seeing the docker network's gateway IP and not the real remote addr. Normally network=host solves the issue, when running a docker container. Is there a way to pass that docker run parameter to railway app?
Thanks. 😃

0 Replies

Anonymous
TRIALOP

2 years ago

71de5038-f8d1-4214-81d4-290481deb483


brody
EMPLOYEE

2 years ago

you would need to have nginx trust the applicable header that cloudflare sets


Anonymous
TRIALOP

2 years ago

I've already done that. It didn't help, because I'm deploying a docker image and docker changes it.

https://forums.docker.com/t/docker-overrides-remote-addr-and-forwarded-for-headers-to-the-bridge-network-ip/138485


brody
EMPLOYEE

2 years ago

I'm sorry but docker is not overriding the CF-Connecting-IP header that cloudflare is setting, you have the wrong idea there


Anonymous
TRIALOP

2 years ago

no docker overwrites the $remote_addr after I've set it with the value from CF-Connecting-IP with nginx. I can reproduce this behaviour locally.


brody
EMPLOYEE

2 years ago

that would be down to a misconfiguration. instead, I highly recommend caddy.
with caddy you can very easily set the header to that of what cloudflare sets

and then set the trusted ips to accept the header from


brody
EMPLOYEE

2 years ago

I have a few example Caddyfiles and straightforward methods to serve your app with caddy, so let me know if you're interested in that!


Anonymous
TRIALOP

2 years ago

I don't have a problem with the configuration, because I'm seeing the value from cloudflare. My problem is that I'm not able to setup a network for my docker image on railway, the way I can set it up locally, by passing --net=host when I run the container.


brody
EMPLOYEE

2 years ago

in NGINX I'm seeing the docker network's gateway IP and not the real remote addr

I don't have a problem with the configuration, because I'm seeing the value from cloudflare

im confused, can you or can you not see the correct ip in your logs?


Anonymous
TRIALOP

2 years ago

No, I can't see the correct IP in my logs.


brody
EMPLOYEE

2 years ago

then why was this said?

I'm seeing the value from cloudflare
you are giving very conflicting information


Anonymous
TRIALOP

2 years ago

that is my problem. and the solution that I've figured out locally was to setup my docker differently. hence the question - is it possible to do that on railway as well


brody
EMPLOYEE

2 years ago

of course not, but with the correct configuration there would be no need to


Anonymous
TRIALOP

2 years ago

ok, and what would be the correct configuration for my case - nginx + angular2 in a docker image?


Anonymous
TRIALOP

2 years ago

I've already set up remote ip mod for nginx and it's working on my local machine


Anonymous
TRIALOP

2 years ago

but only if I add --net=host to docker run


brody
EMPLOYEE

2 years ago

what ip are you seeing then?


Anonymous
TRIALOP

2 years ago

127.0.0.1


brody
EMPLOYEE

2 years ago

yeah thats definitely a misconfiguration, id be happy to help you get this setup with caddy!


Anonymous
TRIALOP

2 years ago

I'm not familiar with caddy, is there no example for nginx?


brody
EMPLOYEE

2 years ago

i dont either of us are too familiar with nginx, i only have examples for caddy, so ill try to get a proof of concept working with caddy


Anonymous
TRIALOP

2 years ago

ok, thanks. I don't think I would be using caddy now. I'll try and figure out a way with nginx.


brody
EMPLOYEE

2 years ago

caddy is pretty simple, may i ask why the want to use nginx instead? its config is obviously giving you a bit of troubles


Anonymous
TRIALOP

2 years ago

because I don't want to switch to yet another new technology and also I'm not convinced that this is a web server/reverse proxy configuration issue, since I'me getting a result by running docker differently.


brody
EMPLOYEE

2 years ago

i assure you this isnt down to railway doing anything incorrectly


Anonymous
TRIALOP

2 years ago

I'm not suggesting that. I just need to understand how railway handles docker networks.


Anonymous
TRIALOP

2 years ago

by default docker uses bridge network


brody
EMPLOYEE

2 years ago

im not seeing how docker comes into play here as long as your configurations are correct, your app sits behind a proxy on railway, and then another proxy from cloudflare, you simply need to trust the local ips and cloudflares ips, then pull the client ip from the header that cloudflare sets



Anonymous
TRIALOP

2 years ago

cloudflare -> docker network -> nginx -> docker container


Anonymous
TRIALOP

2 years ago

in docker network happens the thing that's descriped in the post


brody
EMPLOYEE

2 years ago

cloudflare -> railway proxy -> nginx (your app)


Anonymous
TRIALOP

2 years ago

yes railway proxy also somewhere in between, but I'm sure railway is passing headers correctly. I'm seeing that.


Anonymous
TRIALOP

2 years ago

what's messing the headers is the docker network I think


brody
EMPLOYEE

2 years ago

why not just straight log the header?


brody
EMPLOYEE

2 years ago

please remove this notion of the docker network causing you issues, i get that you can change it locally and have it work, but with the correct configurations you do not need to change the network.

again, i am still offering you a drop in pre-made solution with caddy.


brody
EMPLOYEE

2 years ago

with caddy, logging the client ip thats set by cloudflare is as simple as a 1 line config


Anonymous
TRIALOP

2 years ago

exactly the same thing I'm doing in nginx

setrealip_from
…
trusted ips
…

realipheader cf-connecting-ip;
realiprecursive on;


Anonymous
TRIALOP

2 years ago

🙂


brody
EMPLOYEE

2 years ago

what ips are you trusting?


Anonymous
TRIALOP

2 years ago


Anonymous
TRIALOP

2 years ago

now that you're mentioning it, perhaps I need to trust the railway proxy ips too


brody
EMPLOYEE

2 years ago

I thought you where already doing that, my bad


Anonymous
TRIALOP

2 years ago

In the end it worked by trusting the railway IPs. However the really ngxhttprealipmodule didn't store the value where it says in the documentations it would. Instead in realipremoteaddr it was stored in $remoteaddr. It took me also some time to figure this out. Very strange.

Thank you for talking to me. It helped clearing up the the issue. 😀


brody
EMPLOYEE

2 years ago

happy to help where I can!


Loading...