Opened 10 years ago

Closed 10 years ago

#728 closed defect (wontfix)

alias lost last path character — at Version 2

Reported by: Dmitry Machin Owned by:
Priority: critical Milestone:
Component: other Version: 1.4.x
Keywords: alias autoindex Cc:
uname -a: Linux dimon 3.13.0-46-generic #77-Ubuntu SMP Mon Mar 2 18:23:39 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.4.6 (Ubuntu)
built by gcc 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --add-module=/build/buildd/nginx-1.4.6/debian/modules/nginx-auth-pam --add-module=/build/buildd/nginx-1.4.6/debian/modules/nginx-dav-ext-module --add-module=/build/buildd/nginx-1.4.6/debian/modules/nginx-echo --add-module=/build/buildd/nginx-1.4.6/debian/modules/nginx-upstream-fair --add-module=/build/buildd/nginx-1.4.6/debian/modules/ngx_http_substitutions_filter_module

Description (last modified by Maxim Dounin)

I have nginx config

its part

location ~ ^/api/(?<module>.+)/doc/ {
    autoindex on;
    index index.html;
    alias /home/dmac/www/hub/hub/modules/RestApi/Resources/Doc/$1;
    error_log /var/log/nginx/hub-test-error.log debug;
}

But when i make request, i have error

2015/03/06 18:46:43 [error] 11158#0: *1 opendir() "/home/dmac/www/hub/hub/modules/RestApi/Resources/Doc/dashboar" failed (2: No such file or directory), client: 127.0.0.1, server: hub.dev, request: "GET /api/dashboard/doc/ HTTP/1.1", host: "hub.dev"

OR

2015/03/06 18:29:37 [error] 9941#0: *1 opendir() "/home/dmac/www/hub/hub/modules/RestApi/Resources/Doc/consultan" failed (2: No such file or directory), client: 127.0.0.1, server: hub.dev, request: "GET /api/consultant/doc/ HTTP/1.1", host: "hub.dev"

I try change config

location ~ /api/(consultant|dashboard)/doc/ {

but error the same.

But if i disable "autoindex" i have error

*3 directory index of "/home/dmac/www/hub/hub/modules/RestApi/Resources/Doc/consultant" is forbidden, client: 127.0.0.1, server: hub.dev, request: "GET /test/consultant/doc/ HTTP/1.1", host: "hub.dev"

Nginx has access to this directory.

Change History (2)

comment:1 by Dmitry Machin, 10 years ago

On my work i try this config with nginx/1.7.10 - result the same

comment:2 by Maxim Dounin, 10 years ago

Description: modified (diff)
Resolution: wontfix
Status: newclosed

The problem is that alias set doesn't ends with / for directories. This results in incorrect paths created by index module (it will try to use something like /path/to/directoryindex.html, and also affects how autoindex works (when opening a directory it strips the last character in path, assuming it's /). Trivial fix is to rewrite config to make sure directory paths from alias ends with /, like this:

location ~ ^/api/(?<module>.+/)doc/ {
    autoindex on;
    index index.html;
    alias /home/dmac/www/hub/hub/modules/RestApi/Resources/Doc/$1;
    error_log /var/log/nginx/hub-test-error.log debug;
}

Note well that correct behaviour happens automatically when using root.

Note: See TracTickets for help on using tickets.