<font class="Apple-style-span" face="'trebuchet ms', sans-serif">Thanks for the note and the clever workaround. We were able to tweak this to work with but then it still left a lot of the other functions we were using such as deny/allow, limit_con, ect not working.  Instead we went back to amazon and it turns out they were able to correct the behavior of their load balancer.</font><div>
<font class="Apple-style-span" face="'trebuchet ms', sans-serif"><br></font></div><div><font class="Apple-style-span" face="'trebuchet ms', sans-serif">I wanted to report back on the performance of putting nginx behind an elb.  We compared elb to haproxy and on amazon's cloud we got better performance through the elb than we did an haproxy instance. There is minimal impact on end user performance for adding this extra step.  We did this for redundancy to allow us to automatically fail over to another zone if the current zone or instance go down. </font></div>
<div><font class="Apple-style-span" face="'trebuchet ms', sans-serif"><br></font></div><div><font class="Apple-style-span" face="'trebuchet ms', sans-serif">Happy to answer any questions about the setup.</font></div>
<div><font class="Apple-style-span" face="'trebuchet ms', sans-serif"><br></font></div><div><font class="Apple-style-span" face="'trebuchet ms', sans-serif">Rami</font></div><div><div><font class="Apple-style-span" face="'trebuchet ms', sans-serif"><br>
</font></div><div><font class="Apple-style-span" face="'trebuchet ms', sans-serif"><br></font><div class="gmail_quote">On Sat, Nov 26, 2011 at 3:44 PM, 敬张 <span dir="ltr"><<a href="mailto:911csj@gmail.com">911csj@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">$remote_addr(OSI 3layer) and $http_x_forwarded_for(OSI 7layer) of these two variables is different. behind LB server may be you can use config like this.<br>
http {<br>    map $proxy_add_x_forwarded_for $xff_pass {<br>        default             "xff403";<br>
        ~^61\.152\.90\.8    "xffpass";<br>        ~^61\.172\.241\.    "xffpass";<br>    limit_req_zone          $http_x_forwarded_for zone=one:10m rate=200r/s;<br>    ...<br>    server {<br>        if ($xff_pass !~* xffpass) {<br>

            return             403;<br>        }<br>        limit_req zone=one;<br>        ...<div class="HOEnZb"><div class="h5"><br>    }<br>}<br><br><div class="gmail_quote">2011/11/26 Rami Essaid <span dir="ltr"><<a href="mailto:rami.essaid@gmail.com" target="_blank">rami.essaid@gmail.com</a>></span><br>

<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font color="#000000"><font size="2"><font face="trebuchet ms,sans-serif">As a quick update, it looks like this has happened before. The load balancer bounces off of several internal IP's sometimes and nginx picks the last one only. Does anyone know of a workaround to remove the last two trusted IPs from the x-forwarded-for header?</font></font></font><div>


<font color="#000000"><font size="2"><font face="trebuchet ms,sans-serif"><br></font></font></font></div><div><font color="#000000"><font size="2"><font face="trebuchet ms,sans-serif"><a href="http://forum.nginx.org/read.php?11,26102,214069" target="_blank">http://forum.nginx.org/read.php?11,26102,214069</a></font></font></font></div>

<span><font color="#888888">
<div><font color="#000000"><font size="2"><font face="trebuchet ms,sans-serif"><br></font></font></font></div></font></span><div><span><font color="#888888"><font color="#000000"><font size="2"><font face="trebuchet ms,sans-serif">Rami<br>

</font></font></font></font></span><div><div><br>
<div class="gmail_quote">On Fri, Nov 25, 2011 at 4:54 PM, Rami Essaid <span dir="ltr"><<a href="mailto:rami.essaid@gmail.com" target="_blank">rami.essaid@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">


<font color="#000000"><font size="2"><font face="trebuchet ms,sans-serif">In looking at the $proxy_add_x_forwarded_for variable I believe that the Loadbalancer is in fact passing the variables but nginx is taking the wrong value?  </font></font></font><div>



<font color="#000000"><font size="2"><font face="trebuchet ms,sans-serif"><br></font></font></font></div><div><font color="#000000"><font size="2"><font face="trebuchet ms,sans-serif">Here is what i get from the variables.  </font></font></font></div>



<div><span style="font-family:'trebuchet ms',sans-serif">$proxy_add_x_forwarded_for: <a href="tel:217.27.244.18" value="+12172724418" target="_blank">217.27.244.18</a>, 10.160.43.200, 10.160.43.200</span></div>
<div>
<font face="'trebuchet ms', sans-serif">$remote_addr: 10.160.43.200</font></div>
<div><font face="'trebuchet ms', sans-serif"><br></font></div><div><font color="#000000"><font size="2"><font face="trebuchet ms,sans-serif">Does this mean that nginx is taking the last value in the x-forwarded-for?  </font></font></font></div>



<div><font color="#000000"><font size="2"><font face="trebuchet ms,sans-serif"><br></font></font></font></div><div><font face="'trebuchet ms', sans-serif">To answer your other question, yes, the Amazon plenty of</font> sockets available to connect to nginx.</div>



<div><br></div><div>The reason we added this was to be able to utilize Amazon's auto scaling feature for redundancy and scalability.  We have not been able to test performance yet since we are still trying to make it work but as soon as we do I will be sure to report back.</div>


<div><div>
<div><br></div><br><div class="gmail_quote">On Fri, Nov 25, 2011 at 4:19 PM, Stefan Caunter <span dir="ltr"><<a href="mailto:stef@caunter.ca" target="_blank">stef@caunter.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">



<div>On Fri, Nov 25, 2011 at 12:37 PM, Rami Essaid <<a href="mailto:rami.essaid@gmail.com" target="_blank">rami.essaid@gmail.com</a>> wrote:<br>
> Thanks for the help Maxim!  We disabled our limit_req and that seemed to<br>
> have fixed the problem.  Looking at the logs it seems that only 1/3 of the<br>
> requests are correctly getting the new IP assigned via the realIP module,<br>
> the remainder are still logging the load balancer IP.  This probably is more<br>
> of an issue with the amazon load balancer but do you have any idea on what<br>
> may be going on?<br>
> Also, where would you recommend as a place to start tracking and fixing the<br>
> other issue?<br>
><br>
<br>
</div>You have not established that load balancer is setting X-Forwarded-For<br>
or some other header to pass Real IP.<br>
<br>
Does the amazon pseudo device have enough sockets available to connect to nginx?<br>
<br>
What do you expect from adding this layer? Were you hitting<br>
performance limits? Has it improved or degraded performance?<br>
<div><div><br>
><br>
><br>
> On Fri, Nov 25, 2011 at 12:14 PM, Maxim Dounin <<a href="mailto:mdounin@mdounin.ru" target="_blank">mdounin@mdounin.ru</a>> wrote:<br>
>><br>
>> Hello!<br>
>><br>
>> On Fri, Nov 25, 2011 at 09:54:14AM -0500, Rami Essaid wrote:<br>
>><br>
>> > Hi Maxim,<br>
>> ><br>
>> > We implemented to module and still had some trouble.  A lot of the<br>
>> > connections would return " 503 Service Temporarily Unavailable".  Our<br>
>> > configuration works fine without the load balancer but then gives these<br>
>> > 503<br>
>> > errors behind the load balancer.<br>
>><br>
>> nginx itself will only return 503 if it hits either limit_conn or<br>
>> limit_req.<br>
>><br>
>> If you see this returned by nginx, and it only happens with load<br>
>> balancer, this may indicate you've not configured realip module<br>
>> properly (or your load balancer doesn't provide appropriate<br>
>> headers) and you are hitting per-ip limits configured due to all<br>
>> requests appear to be from load balancer.<br>
>><br>
>> Check if client's ip logged is really client's one, not an ip of<br>
>> your load balancer.<br>
>><br>
>> > Looking into the error logs I notice a lot of these errors both with and<br>
>> > without the load balancer "connect() failed (111: Connection refused)<br>
>> > while<br>
>> > connecting to upstream".  Could this be the reason that we are having<br>
>> > issues?<br>
>><br>
>> Unlikely, but It's a good idea to track and fix this in any case.<br>
>><br>
>> Maxim Dounin<br>
>><br>
>> ><br>
>> > Thanks!<br>
>> > Rami<br>
>> ><br>
>> ><br>
>> > On Mon, Nov 21, 2011 at 7:46 AM, Maxim Dounin <<a href="mailto:mdounin@mdounin.ru" target="_blank">mdounin@mdounin.ru</a>><br>
>> > wrote:<br>
>> ><br>
>> > > Hello!<br>
>> > ><br>
>> > > On Mon, Nov 21, 2011 at 07:40:49AM -0500, Rami Essaid wrote:<br>
>> > ><br>
>> > > > Thanks Maxim,<br>
>> > > ><br>
>> > > > This looks like exactly what we need.  In your experience does this<br>
>> > > resolve<br>
>> > > > most issues behind a load balancer?<br>
>> > ><br>
>> > > Yes.<br>
>> > ><br>
>> > > Maxim Dounin<br>
>> > ><br>
>> > > > On Mon, Nov 21, 2011 at 7:38 AM, Maxim Dounin <<a href="mailto:mdounin@mdounin.ru" target="_blank">mdounin@mdounin.ru</a>><br>
>> > > wrote:<br>
>> > > ><br>
>> > > > > Hello!<br>
>> > > > ><br>
>> > > > > On Mon, Nov 21, 2011 at 07:25:39AM -0500, Rami Essaid wrote:<br>
>> > > > ><br>
>> > > > > > Hi Guys,<br>
>> > > > > ><br>
>> > > > > > This weekend for scalability we tried putting our nginx servers<br>
>> > > behind<br>
>> > > > > > amazon's elastic load balancers and came across a road block: it<br>
>> > > does not<br>
>> > > > > > transparently pass the user IP and header information to nginx.<br>
>> > > > > > This<br>
>> > > > > caused<br>
>> > > > > > issues with several pieces of nginx we use including the IP<br>
>> > > > > > allow /<br>
>> > > deny<br>
>> > > > > > rules, the limit_req module, and the limit_con module.  Has<br>
>> > > > > > anyone<br>
>> > > > > > successfully put nginx behind a load balancer?  Any ideas on how<br>
>> > > > > > to<br>
>> > > make<br>
>> > > > > > this work?<br>
>> > > > ><br>
>> > > > > <a href="http://wiki.nginx.org/HttpRealIpModule" target="_blank">http://wiki.nginx.org/HttpRealIpModule</a><br>
>> > > > ><br>
>> > > > > Maxim Dounin<br>
>> > > > ><br>
>> > > > > _______________________________________________<br>
>> > > > > nginx mailing list<br>
>> > > > > <a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
>> > > > > <a href="http://mailman.nginx.org/mailman/listinfo/nginx" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
>> > > > ><br>
>> > ><br>
>> > > > _______________________________________________<br>
>> > > > nginx mailing list<br>
>> > > > <a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
>> > > > <a href="http://mailman.nginx.org/mailman/listinfo/nginx" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
>> > ><br>
>> > > _______________________________________________<br>
>> > > nginx mailing list<br>
>> > > <a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
>> > > <a href="http://mailman.nginx.org/mailman/listinfo/nginx" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
>> > ><br>
>><br>
>> > _______________________________________________<br>
>> > nginx mailing list<br>
>> > <a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
>> > <a href="http://mailman.nginx.org/mailman/listinfo/nginx" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
>><br>
>> _______________________________________________<br>
>> nginx mailing list<br>
>> <a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
>> <a href="http://mailman.nginx.org/mailman/listinfo/nginx" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
><br>
><br>
> _______________________________________________<br>
> nginx mailing list<br>
> <a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
> <a href="http://mailman.nginx.org/mailman/listinfo/nginx" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
><br>
<br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br></div></div></div>
<br>_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br></blockquote></div><br>
</div></div><br>_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br></blockquote></div><br></div></div>