Home>

I use Laravel, Nginx, Docker. In one query you need to define the IP address of the client that makes a query. My IP address 95.28.212.80. How to get it in the code? I tried:

DD (Request () ->
IP ());
DD (Request () ->
getclientip ());
DD ($ _ Server ['remote_addr']);

Everywhere comes the same value: 172.17.0.1. I tried in the NGINX configuration add:

fastcgi_param remote_addr $ remote_addr;

did not help. docker-compose.yaml:

Doorphone-nginx:
    Image: Nginx: Latest
    Container_Name: Doorphone-nginx
    Ports:
      -"80:80"
      -"443: 443"
    Volumes:
      -$ {nginx_conf}: /etc /nginx /conf.d
      -$ {backend_app}: /var /www
      -$ {nginx_logs}: /var /log /nginx
      -$ {nginx_html}: /usr /share /nginx /html
    Links:
      -Doorphone-PHP
  Doorphone-php:
    Build: ./PHP.
    Container_Name: Doorphone-PHP-FPM
    Volumes:
      -$ {backend_app}: /var /www
    Links:
      -Doorphone-DB
  Doorphone-DB:
  ...

We need to watch your network is configured

Alexey Ten2021-07-20 20:24:23

In the Docker Theory uses iptables and masquerade to routing packages in the container, so you will not see the real IP, even with the correct settings, you can try to run NGINX on the host network or manually configure IPTables

Exploding Kitten2021-07-20 21:52:59