nginx sends 301 redirect for alias in location

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

nginx sends 301 redirect for alias in location

Peter Volkov
Hi. Could you, please, explain. Why nginx sends 301 redirect for the following vhost:

server {
    listen 80;
    server_name test.domain.tv;

    access_log off;

    location = /test/README.txt {
        alias /var/www/;
    }
}

Here is redirect:

 $ http http://test.domain.tv/test/README.txt
HTTP/1.1 301 Moved Permanently
Connection: keep-alive
Content-Length: 178
Content-Type: text/html
Date: Wed, 05 Sep 2018 06:55:27 GMT
Keep-Alive: timeout=20
Location: http://test.domain.tv/test/README.txt/
Server: nginx

<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>




--
Peter.

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: nginx sends 301 redirect for alias in location

Maxim Dounin
Hello!

On Wed, Sep 05, 2018 at 09:58:54AM +0300, Peter Volkov wrote:

> Hi. Could you, please, explain. Why nginx sends 301 redirect for the
> following vhost:
>
> server {
>     listen 80;
>     server_name test.domain.tv <http://test.m9.smotreshka.tv>;
>
>     access_log off;
>
>     location = /test/README.txt {
>         alias /var/www/;
>     }
> }
>
> Here is redirect:
>
>  $ http http://test.domain.tv/test/README.txt
> HTTP/1.1 301 Moved Permanently
> Connection: keep-alive
> Content-Length: 178
> Content-Type: text/html
> Date: Wed, 05 Sep 2018 06:55:27 GMT
> Keep-Alive: timeout=20
> Location: http://test.domain.tv/test/README.txt/
> Server: nginx
>
> <html>
> <head><title>301 Moved Permanently</title></head>
> <body bgcolor="white">
> <center><h1>301 Moved Permanently</h1></center>
> <hr><center>nginx</center>
> </body>
> </html>

You've aliased "/test/README.txt" into a directory "/var/www/".  
Since the URI "/test/README.txt" does not have a trailing slash,
nginx returns a redirect with a trailing slash added, much like it
does when requesting a directory without a trailing shash.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: nginx sends 301 redirect for alias in location

Peter Volkov
On Wed, Sep 5, 2018 at 3:25 PM, Maxim Dounin <[hidden email]> wrote:
On Wed, Sep 05, 2018 at 09:58:54AM +0300, Peter Volkov wrote:

> Hi. Could you, please, explain. Why nginx sends 301 redirect for the
> following vhost:
>
> server {
>     listen 80;
>     server_name test.domain.tv <http://test.m9.smotreshka.tv>;
>
>     access_log off;
>
>     location = /test/README.txt {
>         alias /var/www/;
>     }
> }
>
> Here is redirect:
>
>  $ http http://test.domain.tv/test/README.txt
> HTTP/1.1 301 Moved Permanently
> Connection: keep-alive
> Content-Length: 178
> Content-Type: text/html
> Date: Wed, 05 Sep 2018 06:55:27 GMT
> Keep-Alive: timeout=20
> Location: http://test.domain.tv/test/README.txt/
> Server: nginx
>
> <html>
> <head><title>301 Moved Permanently</title></head>
> <body bgcolor="white">
> <center><h1>301 Moved Permanently</h1></center>
> <hr><center>nginx</center>
> </body>
> </html>

You've aliased "/test/README.txt" into a directory "/var/www/". 
Since the URI "/test/README.txt" does not have a trailing slash,
nginx returns a redirect with a trailing slash added, much like it
does when requesting a directory without a trailing shash.

Thank you, Maxim. That was the problem!

--
Peter.

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx