Forum: NGINX nginx add trailing slash with wrong port

2974d09ac2541e892966b762aad84943?d=identicon&s=25 luc2 (Guest)
on 2014-05-24 20:54
(Received via mailing list)
nginx rewrites :

> http://localhost:8081/files

to :

> http://localhost:81/files/ # wrong port !

while apache rewrites :

> http://localhost:8082/files

to

> http://localhost:8082/files/

is it possible to configure nginx to behave like apache ?

/etc/nginx/conf.d/test.conf :

> server {
>     listen       81;
>     location /files {
>         alias /home/luc2/files;
>         autoindex on;
>     }
> }

/etc/httpd/conf.d/test.conf :

> <VirtualHost *:82>
>     Alias /files /home/luc2/files
>     <Directory /home/luc2/files>
>             Options indexes
>             Allow from all
>     </Directory>
> </VirtualHost>

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,250338,250338#msg-250338
2974d09ac2541e892966b762aad84943?d=identicon&s=25 itpp2012 (Guest)
on 2014-05-24 22:28
(Received via mailing list)
A listen to port 81 should not invoke a response from 8081, check to see
who
is listening on 8081.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,250338,250339#msg-250339
Bb7e85832e0110214043a8726ad70a76?d=identicon&s=25 Dustin Oprea (Guest)
on 2014-05-24 22:36
(Received via mailing list)
On May 24, 2014 2:53 PM, "luc2" <nginx-forum@nginx.us> wrote:
>
> > server {
> >     Alias /files /home/luc2/files
> >     <Directory /home/luc2/files>
> >             Options indexes
> >             Allow from all
> >     </Directory>
> > </VirtualHost>
>
> Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,250338,250338#msg-250338
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

Aliases (and any other configurable sharing a name with something in
Apache) generally don't do the same thing as in Apache. Just use "root"
inside the location block.

Dustin
36a8284995fa0fb82e6aa2bede32adac?d=identicon&s=25 Francis Daly (Guest)
on 2014-05-29 01:01
(Received via mailing list)
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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.