comparison src/http/ngx_http_core_module.c @ 6227:bd55d75a1410

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 4bc94faeff66
children 06e850859a26
comparison
equal deleted inserted replaced
6226:4bc94faeff66 6227:bd55d75a1410
1238 path.len = e.pos - path.data; 1238 path.len = e.pos - path.data;
1239 1239
1240 *e.pos = '\0'; 1240 *e.pos = '\0';
1241 1241
1242 if (alias && alias != NGX_MAX_SIZE_T_VALUE 1242 if (alias && alias != NGX_MAX_SIZE_T_VALUE
1243 && ngx_strncmp(name, clcf->name.data, alias) == 0) 1243 && ngx_strncmp(name, r->uri.data, alias) == 0)
1244 { 1244 {
1245 ngx_memmove(name, name + alias, len - alias); 1245 ngx_memmove(name, name + alias, len - alias);
1246 path.len -= alias; 1246 path.len -= alias;
1247 } 1247 }
1248 } 1248 }
1322 r->uri = path; 1322 r->uri = path;
1323 r->add_uri_to_alias = 1; 1323 r->add_uri_to_alias = 1;
1324 } 1324 }
1325 1325
1326 } else { 1326 } else {
1327 name = r->uri.data;
1328
1327 r->uri.len = alias + path.len; 1329 r->uri.len = alias + path.len;
1328 r->uri.data = ngx_pnalloc(r->pool, r->uri.len); 1330 r->uri.data = ngx_pnalloc(r->pool, r->uri.len);
1329 if (r->uri.data == NULL) { 1331 if (r->uri.data == NULL) {
1330 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); 1332 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1331 return NGX_OK; 1333 return NGX_OK;
1332 } 1334 }
1333 1335
1334 p = ngx_copy(r->uri.data, clcf->name.data, alias); 1336 p = ngx_copy(r->uri.data, name, alias);
1335 ngx_memcpy(p, name, path.len); 1337 ngx_memcpy(p, path.data, path.len);
1336 } 1338 }
1337 1339
1338 ngx_http_set_exten(r); 1340 ngx_http_set_exten(r);
1339 1341
1340 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 1342 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,