<div dir="ltr"><div class="gmail_default" style="font-size:large"># HG changeset patch<br># User spacewander <<a href="mailto:spacewanderlzx@gmail.com">spacewanderlzx@gmail.com</a>><br># Date 1579523127 -28800<br>#      Mon Jan 20 20:25:27 2020 +0800<br># Branch ident<br># Node ID 86dbfc59e9c01608244c4fdc0d9a87fd9d330648<br># Parent  4fb5603514f2d324c50cb7e12c6ed0dc8935de0f<br>Keep remote port unchanged if real address doesn't contain a port.<br><br>Previously, when the request comes from a trusted address and it doesn't contain<br>the port part, the $remote_port will be empty.<br><br>This change has two advantages:<br>1. no need to write your own fallback with $remote_port and $realip_remote_port.<br>2. the $remote_port in the existent code doesn't need to be changed.<br><br>diff -r 4fb5603514f2 -r 86dbfc59e9c0 src/http/ngx_http_core_module.c<br>--- a/src/http/ngx_http_core_module.c    Thu Apr 18 17:59:00 2019 +0800<br>+++ b/src/http/ngx_http_core_module.c   Mon Jan 20 20:25:27 2020 +0800<br>@@ -2683,6 +2683,12 @@<br>         return NGX_DECLINED;<br>     }<br> <br>+    in_port_t port = ngx_inet_get_port(paddr.sockaddr);<br>+    if (port == 0) {<br>+        port = ngx_inet_get_port(addr->sockaddr);<br>+        ngx_inet_set_port(paddr.sockaddr, port);<br>+    }<br>+<br>     *addr = paddr;<br> <br>     if (recursive && p > xff) {</div></div>