comparison src/http/ngx_http_core_module.c @ 6341:2797b4347a2a stable-1.8

Fixed wrong URI after try_files in nested location (ticket #97). The following configuration with alias, nested location and try_files resulted in wrong file being used. Request "/foo/test.gif" tried to use "/tmp//foo/test.gif" instead of "/tmp/test.gif": location /foo/ { alias /tmp/; location ~ gif { try_files $uri =405; } } Additionally, rev. c985d90a8d1f introduced a regression if the "/tmp//foo/test.gif" file was found (ticket #768). Resulting URI was set to "gif?/foo/test.gif", as the code used clcf->name of current location ("location ~ gif") instead of parent one ("location /foo/"). Fix is to use r->uri instead of clcf->name in all cases in the ngx_http_core_try_files_phase() function. It is expected to be already matched and identical to the clcf->name of the right location.
author Maxim Dounin <mdounin@mdounin.ru>
date Sun, 16 Aug 2015 10:51:34 +0300
parents 312472807db8
children
comparison
equal deleted inserted replaced
6340:312472807db8 6341:2797b4347a2a
1271 path.len = e.pos - path.data; 1271 path.len = e.pos - path.data;
1272 1272
1273 *e.pos = '\0'; 1273 *e.pos = '\0';
1274 1274
1275 if (alias && alias != NGX_MAX_SIZE_T_VALUE 1275 if (alias && alias != NGX_MAX_SIZE_T_VALUE
1276 && ngx_strncmp(name, clcf->name.data, alias) == 0) 1276 && ngx_strncmp(name, r->uri.data, alias) == 0)
1277 { 1277 {
1278 ngx_memmove(name, name + alias, len - alias); 1278 ngx_memmove(name, name + alias, len - alias);
1279 path.len -= alias; 1279 path.len -= alias;
1280 } 1280 }
1281 } 1281 }
1355 r->uri = path; 1355 r->uri = path;
1356 r->add_uri_to_alias = 1; 1356 r->add_uri_to_alias = 1;
1357 } 1357 }
1358 1358
1359 } else { 1359 } else {
1360 name = r->uri.data;
1361
1360 r->uri.len = alias + path.len; 1362 r->uri.len = alias + path.len;
1361 r->uri.data = ngx_pnalloc(r->pool, r->uri.len); 1363 r->uri.data = ngx_pnalloc(r->pool, r->uri.len);
1362 if (r->uri.data == NULL) { 1364 if (r->uri.data == NULL) {
1363 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); 1365 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1364 return NGX_OK; 1366 return NGX_OK;
1365 } 1367 }
1366 1368
1367 p = ngx_copy(r->uri.data, clcf->name.data, alias); 1369 p = ngx_copy(r->uri.data, name, alias);
1368 ngx_memcpy(p, name, path.len); 1370 ngx_memcpy(p, path.data, path.len);
1369 } 1371 }
1370 1372
1371 ngx_http_set_exten(r); 1373 ngx_http_set_exten(r);
1372 1374
1373 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 1375 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,