我檢查IP地址在控制器錯誤nginx的+獨角獸+ IP地址軌
request.env['REMOTE_ADDR']
能正常工作在我的測試環境。 但是在帶有nginx + unicorn的生產服務器上,我總是得到127.0.0.1
。
這是我的網站nginx的配置:
upstream unicorn {
server unix:/tmp/unicorn.urlshorter.sock fail_timeout=0;
}
server {
listen 80 default deferred;
# server_name example.com;
root /home/deployer/apps/urlshorter/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
不是因爲這種方法的大風扇不在我的開發環境中使用的工作薄。 – dgmdan
你說得對。我已經解決了答案。 – forker