<div dir="ltr">Hi <div><br></div><div><div>I am trying to setup nginx as a UDP load balancer using ngx_stream_core_module to load balance udp traffic across backend instances. </div><div><br></div><div>However, i see that for every incoming UDP packet from a client, nginx uses a different source port when sending the packet to the backend instance for the same UDP connection. That is throwing the backend off. I dont want to use nginx as a transparent proxy to avoid setting up routes (since i am deploying on Google Cloud). Is there a way nginx can load balancer based on the UDP connection?</div><div><br></div><div>I am using the following config:</div><div><br></div><div>
<p class="gmail-p1"><span class="gmail-s1">upstream test_upstreams {</span></p>
<p class="gmail-p1"><span class="gmail-s1"><span class="gmail-Apple-converted-space"> </span>server <a href="http://104.199.242.111:6121">104.199.242.111:6121</a>;</span></p>
<p class="gmail-p1"><span class="gmail-s1"><span class="gmail-Apple-converted-space"> </span>server <a href="http://104.199.242.111:6122">104.199.242.111:6122</a>;</span></p>
<p class="gmail-p1"><span class="gmail-Apple-converted-space"> </span>hash $remote_addr consistent;<br></p>
<p class="gmail-p1"><span class="gmail-s1"><span class="gmail-Apple-converted-space"> </span>}</span></p>
<p class="gmail-p2"><span class="gmail-s1"></span><br></p>
<p class="gmail-p1"><span class="gmail-s1"><span class="gmail-Apple-converted-space"> </span>server {</span></p>
<p class="gmail-p1"><span class="gmail-s1"><span class="gmail-Apple-converted-space"> </span>listen 443 udp;</span></p>
<p class="gmail-p2"><span class="gmail-Apple-converted-space"> </span>preread_buffer_size 1500;</p>
<p class="gmail-p1"><span class="gmail-s1"><span class="gmail-Apple-converted-space"> </span>proxy_pass test_upstreams;</span></p>
<p class="gmail-p1"><span class="gmail-s1"><span class="gmail-Apple-converted-space"> </span>proxy_timeout 10s;</span></p>
<p class="gmail-p1"><span class="gmail-Apple-converted-space"> </span>proxy_responses 1;<br></p>
<p class="gmail-p2"><span class="gmail-Apple-converted-space"> </span>access_log logs/quic_access.log quic;<br><span class="gmail-s1"></span></p>
<p class="gmail-p1"><span class="gmail-s1"><span class="gmail-Apple-converted-space"> </span>error_log logs/udp.log;</span></p>
<p class="gmail-p1"><span class="gmail-s1"><span class="gmail-Apple-converted-space"> </span>}</span></p></div><h2 style="text-align:center;color:rgb(0,0,0);font-family:sans-serif"><br><br></h2><div>Thanks</div><div>Rajesh</div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div style="width:559.047px;display:inline-block;padding-left:24px;vertical-align:top;font-size:16px;color:rgb(51,51,51);font-family:ff-clan-web-pro,"Helvetica Neue",Helvetica,sans-serif"></div></div></div></div></div></div></div>
</div></div>