How to solve this problem? After I connected the unicorn to the production server in my logs it is clear that all requests to the application go through ip 127.0.0.1 and even Devise registers current_sign_in_ip as 127.0.0.1

Started GET "/users/sign_in" for 127.0.0.1 at 2016-03-22 09:09:35 +0100 Started GET "/" for 127.0.0.1 at 2016-03-22 09:09:39 +0100 

nginx.conf

 worker_processes 1; error_log logs/error.log; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; gzip on; upstream app_production { server unix:/tmp/unicorn.app_production.sock fail_timeout=0; } server { listen 80; server_name app.exemple.com; root /home/deployer/app_production/current/public; rails_env production; client_max_body_size 50M; location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } try_files $uri/index.html $uri @app_production; location @app_production { proxy_set_header X-Forwared-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://app_production; } } } 

Closed due to the fact that off-topic participants D-side , zRrr , aleksandr barakin , user194374, Grundy Apr 7 '16 at 19:04 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - D-side, zRrr, aleksandr barakin, Community Spirit, Grundy
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Nginx restarted? Unicorn? configs to bases correctly spelled? - Danil Artemev
  • Yes, I restarted, even rebuilt a server - Mikhail Lutsko

1 answer 1

You can build on the following configuration

 worker_processes 1; error_log logs/error.log; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; gzip on; upstream app_production { server unix:/tmp/unicorn.app_production.sock fail_timeout=0; } server { listen 80; server_name app.exemple.com; root /home/deployer/app_production/current/public; rails_env production; client_max_body_size 50M; location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; } try_files $uri/index.html $uri @app_production; location @app_production { proxy_redirect off; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header CLIENT_IP $remote_addr; proxy_pass http://app_production; } } } 
  • and again, nothing seems to need to close the question, since the Internet describes exactly the same thing that you describe, but for some reason it does not help me ((( - Mikhail Lutsko
  • I found a clean server with the same problem, in the unicorn 127.0.0.1 logs from nginx, added proxy_set_header from the above config, rebooted nginx and the client’s IP address was transferred to me. Look at the nginx logs - the client’s address is exactly there, may he also have problems obtaining an IP address? Can't you see a reverse proxy in front of him, which does not correctly convey the client's IP address to your nginx? - cheops
  • nginx 81.25.228.220 - - [22/Mar/2016:14:19:02 +0100] "GET /api/v1/airports HTTP/1.1" 304 0 "http://app.example.com/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36" log 81.25.228.220 - - [22/Mar/2016:14:19:02 +0100] "GET /api/v1/airports HTTP/1.1" 304 0 "http://app.example.com/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36" - Mikhail Lutsko
  • log unicorn 127.0.0.1 - - [22/Mar/2016:14:22:28 +0100] "GET / HTTP/1.0" 200 - 0.0362 - Mikhail Lutsko
  • log rails I, [2016-03-22T14:24:28.139162 #1312] INFO -- : Started GET "/" for 127.0.0.1 at 2016-03-22 14:24:28 +0100 - Mikhail Lutsko