As for Docker + Nginx + PHP-Fpm to get the real user IP?

How do I send the real user IP to the container? Now get this:
"SERVER_PORT": "80",
"REMOTE_PORT": "44034",

version: "3.7"
 image: nginx:alpine
 - .:/application
 - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
 - mode: host
 protocol: tcp
 published: 3000
 target: 80
 - backend
 - php-fpm

 build: docker/php-fpm
 - .:/application
 - backend

 driver: bridge

server {
 listen 80 default;

 client_max_body_size 108M;

 access_log /application/logs/nginx-access.log;
 error_log /application/logs/nginx-error.log;

 root /application/www;
 index index.php;

 location / {
 proxy_set_header Host $Host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header X-Forwarded-Proto $scheme;

 try_files $uri $uri/ /index.php?$args;

 location ~ \.php$ {
 location php-fpm:9000;
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 fastcgi_param PHP_VALUE "error_log=/var/log/nginx/application_php_errors.log";
 fastcgi_buffers directives 16 16k;
 set by the fastcgi_buffer_size 32k;
 include fastcgi_params;
March 12th 20 at 09:01
1 answer
March 12th 20 at 09:03
proxy_set_header X-Real-IP $remote_addr;
It already is my default.conf. - Sandrine commented on March 12th 20 at 09:06
This is setting the header X-Real-IP when proxying to your php-fpm - Bernadine_Grimes commented on March 12th 20 at 09:09
@Sandrine, and what you have in this title? - kendall commented on March 12th 20 at 09:12
@kendall, it is not there. That's all that comes to the server:
HOSTNAME": "328004e2eed6",
"TERM": "linux",
"PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"PWD": "/application",
"SHLVL": "1",
"HOME": "/var/www",
"_": "/usr/sbin/php-fpm7.1",
"USER": "www-data",
"HTTP_CACHE_CONTROL": "max-age=0",
"HTTP_CONNECTION": "keep-alive",
"HTTP_DNT": "1",
"HTTP_ACCEPT_ENCODING": "gzip, deflate",
"HTTP_ACCEPT_LANGUAGE": "en-US,en;q=0.5",
"HTTP_ACCEPT": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"HTTP_USER_AGENT": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:62.0) Gecko/20100101 Firefox/62.0",
"HTTP_HOST": "localhost:3000",
"SERVER_PORT": "80",
"REMOTE_PORT": "44802",
"SERVER_SOFTWARE": "nginx/1.15.5",
"DOCUMENT_ROOT": "/application/www",
"DOCUMENT_URI": "/index.php",
"SCRIPT_NAME": "/index.php",
"PHP_VALUE": "error_log=/var/log/nginx/application_php_errors.log",
"SCRIPT_FILENAME": "/application/www/index.php",
"PHP_SELF": "/index.php",
"REQUEST_TIME_FLOAT": 1539492336.682307,
"REQUEST_TIME": 1539492336
- Sandrine commented on March 12th 20 at 09:15
Hmm, so you have the same fastcgi. Proxy_set_header here at all does not work. You need to add fastcgi_param with the correct information - kendall commented on March 12th 20 at 09:18
But I suspect that the external ip was lost somewhere in NAT-f Docker - kendall commented on March 12th 20 at 09:21
@kendall, most likely, why ask the question here. - Sandrine commented on March 12th 20 at 09:24

Find more questions by tags DockerNginxPHP