Why is php-fpm getting the wrong client ip address?
Good day!
I have two docker containers php-fpm
and nginx
I need to get the real ip address of the client, but instead of 127.0.0.1 (localhost) I get 172.0.0.1 what could be the problem?
Below I have indicated the configuration that I am using, as well as a picture so that you could understand me better.
how i see interaction. Smile-client
version: "3.9"
services:
nginx:
build: ./nginx
ports:
- 80:80
volumes:
- ./nginx/conf/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/conf/hosts:/etc/hosts
- ./app:/var/www/app
networks:
- app_network
php-fpm:
build: ./phpfpm
depends_on:
- nginx
volumes:
- ./phpfpm/conf/www.conf:/usr/local/etc/php-fpm.d/www.conf
- ./phpfpm/conf/hosts:/etc/hosts
- ./app:/var/www/app
networks:
- app_network
networks:
app_network:
ipam:
driver: default
config:
- subnet: "172.0.0.0/24"
- subnet: "2001:3984:3989::/64"
as you can see I have merged host port 80 with container port 80 so I expect the correct ip to be passed. What am I doing wrong? I would be grateful for any answer, thanks in advance !!
Solution 1:
What you are asking for are martian packets. A sane kernel won't let you do this. The loopback is virtual and strictly local.
You should be able though to pass your other IP address to the subnet when you access the mapped port at that IP.