{"id":14466,"date":"2014-06-30T23:49:44","date_gmt":"2014-06-30T18:19:44","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=14466"},"modified":"2014-06-30T23:49:44","modified_gmt":"2014-06-30T18:19:44","slug":"getting-real-ip-while-using-nginx-working-behind-amazon-elastic-load-balancer","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/getting-real-ip-while-using-nginx-working-behind-amazon-elastic-load-balancer\/","title":{"rendered":"Getting real IP while using nginx working behind Amazon Elastic Load Balancer"},"content":{"rendered":"<p><span>When placing nginx \u00a0web servers behind a Elastic load balancer\u00a0\u00a0, the client IP address from the browser is replaced with the IP address of the load-balancer. This makes difficult to analysis the location of IP<\/span><\/p>\n<p><span style=\"color: #141412\">Here\u2019s how you can fix it and capture the real IP.<\/span><\/p>\n<p><span>Prerequisite<\/span><\/p>\n<p><span>Make sure you have\u00a0<\/span><strong>http_realip_module <\/strong>with\u00a0nginx<strong>\u00a0<\/strong><span>. You can check it this way:<\/span><\/p>\n<pre><span>nginx -V<\/span><\/pre>\n<p>&nbsp;<\/p>\n<p><span>Open \/etc\/nginx\/nginx.conf file and add following parameters inside http block.<\/span><\/p>\n<pre>vi\u00a0\/etc\/nginx\/nginx.conf\r\n\r\nhttp { ..\r\nreal_ip_header X-Forwarded-For;\r\nset_real_ip_from 0.0.0.0\/0;\r\n..}<\/pre>\n<p>&nbsp;<\/p>\n<p><span>After this reload the nginx and check the access logs.<\/span><\/p>\n<p><span>Note : If the traffic \u00a0only coming through elastic load balancer , then set\u00a0\u00a0IP address assigned to elastic load balancer.<\/span><\/p>\n<p><span>Suppose IP address for elastic load balance\u00a0 is 1.1.1.1, then it should look like<\/span><\/p>\n<pre>set_real_ip_from 1.1.1.1;<\/pre>\n<address>\u00a0<\/address>\n<address>Thanks<\/address>\n<address>Prashant Sharma<\/address>\n","protected":false},"excerpt":{"rendered":"<p>When placing nginx \u00a0web servers behind a Elastic load balancer\u00a0\u00a0, the client IP address from the browser is replaced with the IP address of the load-balancer. This makes difficult to analysis the location of IP Here\u2019s how you can fix it and capture the real IP. Prerequisite Make sure you have\u00a0http_realip_module with\u00a0nginx\u00a0. You can check [&hellip;]<\/p>\n","protected":false},"author":120,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":19},"categories":[1174],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/14466"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/120"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=14466"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/14466\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=14466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=14466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=14466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}