[PATCH v4 07/12] Static: add "index" option

Valentin V. Bartenev vbart at nginx.com
Mon Feb 14 12:12:51 UTC 2022


On Monday, 14 February 2022 14:33:21 MSK Alejandro Colomar (man-pages) wrote:
[..]
> > 3) router crash when variable in index value is empty
> 
> The same behavior happens when you set up index to the name of a dir:
> 
> $ cat config.json
> {
> 	"listeners": {
> 		"*:80": {
> 			"pass": "routes"
> 		}
> 	},
> 
> 	"routes": [
> 		{
> 			"action": {
> 				"share": "/home/alx/srv/www/static/$uri",
> 				"index": "dir"
> 			}
> 		}
> 	]
> }
> $ ls -l /home/alx/srv/www/static/
> total 16
> -rw-r--r-- 1 alx alx    4 Dec 14 17:51 GET.html
> drwxr-xr-x 2 alx alx 4096 Feb 14 12:18 dir
> -rw-r--r-- 1 alx alx    6 Dec 14 17:52 index.html
> -rw-r--r-- 1 alx alx   10 Dec 15 12:55 localhost.html
> 
> 
> $ curl --dump-header - http://localhost
> HTTP/1.1 301 Moved Permanently
> Location: //
> Server: Unit/1.27.0
> Date: Mon, 14 Feb 2022 11:19:24 GMT
> Content-Length: 0
> 
> 
> Setting "dir/" instead of "dir" behaves identically too.
> 
> What is the expected behavior when trying to serve a directory?  With 
> old nginx (open-source), with autoindex off, and try_files ${uri}/, I'm 
> getting 403 Forbidden.  Where does Unit decide about that? 
[..]

I think there shouldn't be any differences between different situations
when "index" doesn't point to an accessible file.  That can be a directory
or can be a socket, for example.

Both Unit and nginx return in similar cases 404:

    if (!of.is_file) {
        ngx_log_error(NGX_LOG_CRIT, log, 0,
                      "\"%s\" is not a regular file", path.data);

        return NGX_HTTP_NOT_FOUND;
    }

--
        if (nxt_slow_path(!nxt_is_dir(&fi))) {
            nxt_log(task, NXT_LOG_ERR, "\"%FN\" is not a regular file",
                    f->name);

            nxt_http_static_next(task, r, ctx, NXT_HTTP_NOT_FOUND);
            return;
        }

Because it's like the file was requested (or indirectly requested via "index"),
but no file was found by that name.

--
Valentin





More information about the unit mailing list