Client specified server port

ryd994 ryd994 at 163.com
Tue Aug 25 02:55:54 UTC 2015


Hi,

Maybe you can use following config which is shorter and does not use the
evil "if".

map $http_host $redirect_port {
  default   "";
  .*(:\d+)  $1;
}

return 302 $scheme://$host$redirect_port/<your URL>

On Tue, Aug 25, 2015, 06:35 Joó Ádám <adam at jooadam.hu> wrote:

> Hi,
>
> The return directive allows the use of URLs relative to the server, in
> which case the scheme, server name and port are automatically
> prepended by Nginx.
>
> The port is, however, the port on which the request was received,
> which is not always the port to which the request was sent, i. e. the
> one specified in the Host header field. For example, tunneling
> nginx.org:80 through example.com:8000 a redirect will lead to
> example.com:80.
>
> Also, there is no variable exposing this value, so one must extract it
> themselves to explicitly specify in the redirect URL:
>
>     set $is_port '';
>     set $port '';
>
>     if ($http_host ~ :(\d+)$) {
>         set $is_port ':';
>         set $port $1;
>     }
>
> Maybe this is something that would worth considering as an
> enhancement. Making return use the port in the Host header or to
> preserve backwards compatibility, introducing a switch,
> request_port_in_redirect, complementing server_name_in_redirect, off
> by default, and at the same time exposing this in a $request_port
> variable.
>
> What do you think?
>
>
> Ádám
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20150825/6092461c/attachment.html>


More information about the nginx mailing list