Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: rayarachelian on January 20, 2019, 11:43:49 AM

Title: X-Real-Ip/X-Forwarded-For support?
Post by: rayarachelian on January 20, 2019, 11:43:49 AM
I'm running SMF 2.0.15 in Docker behind an nginx proxy, which adds X-Forwarded-For and X-Real-Ip headers, however SMF shows all users as logged in from the docker proxy IP (172.16.x.x.)

How do I get it to recognize the X-Forwarded-For or X-Real-Ip headers and use those for users instead?

I'm using a modified version of this repo: https://github.com/vortexau/SMF-Docker which creates an Apache 2 instance where the default website is pointing at /var/www/html inside the container.

On the outside, nginx does a reverse proxy to the container and adds these headers.
Title: Re: X-Real-Ip/X-Forwarded-For support?
Post by: vbgamer45 on January 20, 2019, 12:24:10 PM
This might be hepful https://support.cloudflare.com/hc/en-us/articles/200170706-How-do-I-restore-original-visitor-IP-with-Nginx-

You can also add to your settings.php a php code that checks if those headers are set then overwrite the php ip address.
Title: Re: X-Real-Ip/X-Forwarded-For support?
Post by: rayarachelian on January 21, 2019, 06:32:54 PM
This seems to have worked perfectly with only minor changes on the apache side. (For anyone else reading this, again, nginx is on the outside acting as a reverse proxy, apache is on the inside of the Docker container, and runs SMF)

1. enable remoteip by linking mods-available/remoteip to mods-enabled.
2. add RemoteIPHeader X-Real-IP to httpd.conf