造成该问题的一种可能的情形是,设置header的时候,使用了$host变量,即
proxy_set_header Host $host;
它的值是不包含端口的,从而造成了端口丢失的问题。
若需要保留端口,则应使用$http_host变量,即
proxy_set_header Host $http_host;

参考:

  1. http://nginx.org/en/docs/http/ngx_http_core_module.html#var_host
  2. https://stackoverflow.com/a/15414811/8859991