Welcome! Log In Create A New Profile

Advanced

Re: nginx add trailing slash with wrong port

Francis Daly
May 28, 2014 07:02PM
On Sat, May 24, 2014 at 02:53:21PM -0400, luc2 wrote:

Hi there,

> nginx rewrites :
>
> > http://localhost:8081/files
>
> to :
>
> > http://localhost:81/files/ # wrong port !
<snip>
> is it possible to configure nginx to behave like apache ?

No.

If your use case is restricted to one of the two mentioned below, then
you might be able to fake it adequately.

nginx does not have a config option to do what you seem to want, which
is "use the incoming http Host: header value in any generated Location:
response header".

Using "port_in_redirect", you can auto-include either no port at all,
or whichever port the connection actually came to nginx on (which will
be one of the ports listed or implied in the "listen" directives).

If you don't want to patch the code to add your use case, then

* if you have a fixed list of redirections, you could add a number of
locations of the form

location = /dir1 { return 301 $scheme://$http_host/dir1/; }

* or if there is exactly one host/port that you will always want to return
(e.g. server:8081), then you could

port_in_redirect off;
server_name_in_redirect on;
server_name server:8081;

But otherwise, I don't think it can be done.

f
--
Francis Daly francis@daoine.org

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

nginx add trailing slash with wrong port

luc2 May 24, 2014 02:53PM

Re: nginx add trailing slash with wrong port

itpp2012 May 24, 2014 04:27PM

Re: nginx add trailing slash with wrong port

Dustin Oprea May 24, 2014 04:36PM

Re: nginx add trailing slash with wrong port

Francis Daly May 28, 2014 07:02PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 322
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready