[PATCH v4 07/12] Static: add "index" option
Alejandro Colomar (man-pages)
alx.manpages at gmail.com
Mon Feb 14 17:22:28 UTC 2022
On 2/14/22 15:14, Alejandro Colomar (man-pages) wrote:
> I could reproduce the 301 behavior in nginx with a clean debian nginx
> install, by changing the index line in
> </etc/nginx/sites-available/default>:
>
> ...
> # index index.html index.htm index.nginx-debian.html;
> index dir;
> ...
>
> And then create a directory 'dir' in </var/www/html> (which is the 'root'):
>
> $ sudo mkdir /var/www/html/dir
> $ sudo systemctl reload nginx
>
> After that, a curl on localhost gives 301 Moved Permanently, exactly as
> in Unit after the proposed patch set.
>
>
> Regards,
>
> Alex
>
Full config file:
$ cat /etc/nginx/sites-available/default | grep -v '\s*#'
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index dir;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}
$ ls -l /var/www/html/
total 8
drwxr-xr-x 2 root root 4096 Feb 14 14:56 dir
-rw-r--r-- 1 root root 612 Feb 14 14:40 index.nginx-debian.html
$ curl localhost
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.18.0</center>
</body>
</html>
$ sudo mv /var/www/html/dir /var/www/directory
user at sqli:/etc/nginx/sites-available$ curl localhost
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.18.0</center>
</body>
</html>
So if nginx tries to serve a nonexisting file, I get 403, but if it
tries to serve a directory (and autoindex is off), I get 301.
--
Alejandro Colomar
Linux man-pages comaintainer; http://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
More information about the unit
mailing list