実際の訪問者のIPアドレスをUnicornに転送するにはどうすればよいですか?現在の設定は次のとおりです。
Haproxy => Nginx => Unicorn
Haproxy Config:
# haproxy config
defaults
log global
mode http
option httplog
option dontlognull
option httpclose
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
# Rails Backend
backend deployer-production
reqrep ^([^\ ]*)\ /api/(.*) \1\ /\2
balance roundrobin
server deployer-production localhost:9000 check
Nginx構成:
upstream Unicorn-production {
server unix:/tmp/Unicorn.ordify-backend-production.sock fail_timeout=0;
}
server {
listen 9000 default;
server_name manager.ordify.localhost;
root /home/deployer/apps/ordify-backend-production/current/public;
access_log /var/log/nginx/ordify-backend-production_access.log;
rewrite_log on;
try_files $uri/index.html $uri @Unicorn;
location @Unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_Host;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_pass http://Unicorn-production;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
option forwardfor
をHaproxyconfigに追加し、nginx realipモジュールを構成する必要があります: http://nginx.org/en/docs/http/ngx_http_realip_module.html