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

Alejandro Colomar (man-pages) alx.manpages at gmail.com
Mon Feb 14 14:14:41 UTC 2022


On 2/14/22 13:12, Valentin V. Bartenev wrote:
> 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.

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

-- 
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