diff options
Diffstat (limited to 'src/http/modules/ngx_http_static_handler.c')
-rw-r--r-- | src/http/modules/ngx_http_static_handler.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_handler.c index 7876d2a24..0576255eb 100644 --- a/src/http/modules/ngx_http_static_handler.c +++ b/src/http/modules/ngx_http_static_handler.c @@ -60,7 +60,7 @@ ngx_module_t ngx_http_static_module = { static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) { - char *last; + u_char *last; ngx_fd_t fd; ngx_int_t rc; ngx_uint_t level; @@ -115,14 +115,31 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) * in a possible redirect and for the last '\0' */ - name.data = ngx_palloc(r->pool, clcf->doc_root.len + r->uri.len + 2); + name.data = ngx_palloc(r->pool, clcf->root.len + r->uri.len + 2 + - clcf->alias * clcf->name.len); if (name.data == NULL) { return NGX_HTTP_INTERNAL_SERVER_ERROR; } - location.data = ngx_cpymem(name.data, clcf->doc_root.data, - clcf->doc_root.len); - last = ngx_cpystrn(location.data, r->uri.data, r->uri.len + 1); + location.data = ngx_cpymem(name.data, clcf->root.data, clcf->root.len); + + if (clcf->alias) { + last = ngx_cpystrn(location.data, r->uri.data + clcf->name.len, + r->uri.len + 1 - clcf->name.len); + + /* + * aliases usually have trailling "/", + * set it in the start of the possible redirect + */ + + if (*location.data != '/') { + location.data--; + } + + } else { + last = ngx_cpystrn(location.data, r->uri.data, r->uri.len + 1); + } + name.len = last - name.data; location.len = last - location.data + 1; |