• 02 nginx 中几种 location 表达式的优先级问题


    前言

    // 无论贫穷富贵, 家能给与我们的都是一样的 

    呵呵 这是一个 老生常谈的问题 

    从官方文档, 或者 各种博客 中都可以找到这个问题的相关描述 

    我们这里 只关注 location 上面的这五种写法, 不关注 location @name 

    可以看到的是 存在五种写法 

    从下面文档也可以看出 优先级大概是 精确匹配 > 前缀匹配2 > 正则匹配, 忽略大小写正则匹配 > 前缀匹配1 

    我们这里 核心关注的就是 这个顺序是如何实现的?

    以下截图, 调试基于 nginx-1.18.0

    1. location /api // 前缀匹配1
    2. location = /api // 精确匹配
    3. location ^~ /api // 前缀匹配2
    4. location ~ /api // 正则匹配
    5. location ~* /api // 忽略大小写正则匹配

    测试用例 

    这里构造了一下 几种 location 都存在的配置 

    1. server {
    2. listen 80;
    3. server_name localhost;
    4. #charset koi8-r;
    5. #access_log logs/host.access.log main;
    6. location / {
    7. root html;
    8. index index.html index.htm;
    9. }
    10. #error_page 404 /404.html;
    11. # redirect server error pages to the static page /50x.html
    12. #
    13. error_page 500 502 503 504 /50x.html;
    14. location = /50x.html {
    15. root html;
    16. }
    17. location ^~ /api/ {
    18. root html;
    19. index index.html index.htm;
    20. proxy_pass http://localhost:8080/;
    21. }
    22. location = /exactly.html {
    23. root html/exactly;
    24. index index.html index.htm;
    25. }
    26. location ^~ /exactly.html {
    27. root html/exactly;
    28. index index.html index.htm;
    29. }
    30. location ~ /regex.* {
    31. root html/regex;
    32. index index.html index.htm;
    33. }
    34. location ~* /RgxIgnoreCase.* {
    35. root html/regexIgnoreCase;
    36. index index.html index.htm;
    37. }
    38. }

    ngx_http_core_find_location 

    这个函数是 查询 location 的主要驱动 

    ngx_http_core_find_static_location 是查询前缀匹配相关的 locations 

    pclcf->regex_locations 是查询正则匹配相关的 locations 

    首先是查询 前缀匹配相关的 locations 

    如果是 匹配到 "location =", ngx_http_core_find_static_location 响应的是 NGX_OK, 这里直接响应 匹配到的结果, 速度最快 

    如果是 匹配到 "location ~^", ngx_http_core_find_static_location 响应的是 NGX_AGAIN | NGX_DECLINED, 但是它的 noregex 为 1, 因此 会跳过后面的 正则匹配相关 

    如果 匹配到  "location ", ngx_http_core_find_static_location 响应的是 NGX_AGAIN | NGX_DECLINED, 但是它的 noregex 为 0, 因此 如果接下来会尝试正则匹配, 如果匹配上使用 正则的结果, 如果匹配不上, 使用 "location " 匹配到的结果 

    如果 匹配到 "location ~", "location ~*", 那么走的是 下面的正则匹配相关, 结果为 正则匹配到的 loc_conf 

    ngx_http_core_find_static_location 这里面就是根据当前 uri 和前缀树进行匹配 

    如果是 uri 和 node->name 不匹配, 则根据大小 向左或者向右 迭代 node 节点 

    否则 uri 是 node->name 的一部分, 或者 node->name 是 uri 的一部分, 或者 完全匹配

    如果 node->name 是 uri 的一部分, 继续向右迭代, 保留当前记录作为 最长匹配

    如果 node->name 和 uri 完全匹配, 如果存在精确匹配, 则返回 NGX_OK 

            如果是 其他前缀匹配, 则记录当前记录作为最长匹配

    如果 uri 是 node->name 的一部分, 继续向左迭代 

            这里有一个 auto_redirect 的配置是使用于 uri 为 "/api", 然后存在 "location /api/", "location ^~ /api/" 的场景, 这里之所以没有校验配置的最后一位为 "/", 是一位配置 auto_redirect 的地方会进行校验 

    对应于这里前缀匹配有 "location /", "location = /50x.html", "location ^~ /api/", "location = /exactly.html", "location ^~ /exactly.html"

    构造出来的匹配树如下 

    1. # pclcf->static_locations 的 pattern 树如下
    2. / -> null, "/api/", null
    3. "/api/" -> "/50x.html", null, "/exactly.html"
    4. (gdb) print pclcf->static_locations
    5. $16 = (ngx_http_location_tree_node_t *) 0x7fa048023f10
    6. (gdb) print pclcf->static_locations->name
    7. $17 = "/"
    8. (gdb) print pclcf->static_locations->left
    9. $18 = (ngx_http_location_tree_node_t *) 0x0
    10. (gdb) print pclcf->static_locations->tree
    11. $19 = (ngx_http_location_tree_node_t *) 0x7fa048023f40
    12. (gdb) print pclcf->static_locations->right
    13. $20 = (ngx_http_location_tree_node_t *) 0x0
    14. (gdb) print pclcf->static_locations->tree->name
    15. $21 = "a"
    16. (gdb) print pclcf->static_locations->tree->left
    17. $22 = (ngx_http_location_tree_node_t *) 0x7fa048023f70
    18. (gdb) print pclcf->static_locations->tree->tree
    19. $23 = (ngx_http_location_tree_node_t *) 0x0
    20. (gdb) print pclcf->static_locations->tree->right
    21. $24 = (ngx_http_location_tree_node_t *) 0x7fa048023fa8
    22. (gdb) print pclcf->static_locations->tree->left->name
    23. $25 = "5"
    24. (gdb) print pclcf->static_locations->tree->left->left
    25. $26 = (ngx_http_location_tree_node_t *) 0x0
    26. (gdb) print pclcf->static_locations->tree->left->tree
    27. $27 = (ngx_http_location_tree_node_t *) 0x0
    28. (gdb) print pclcf->static_locations->tree->left->right
    29. $28 = (ngx_http_location_tree_node_t *) 0x0
    30. (gdb) print pclcf->static_locations->tree->right->name
    31. $29 = "e"
    32. (gdb) print pclcf->static_locations->tree->right->left
    33. $30 = (ngx_http_location_tree_node_t *) 0x0
    34. (gdb) print pclcf->static_locations->tree->right->tree
    35. $31 = (ngx_http_location_tree_node_t *) 0x0
    36. (gdb) print pclcf->static_locations->tree->right->right
    37. $32 = (ngx_http_location_tree_node_t *) 0x0
    38. (gdb) print pclcf->static_locations->exactly->name
    39. There is no member named exactly.
    40. (gdb) print pclcf->static_locations->inclusive->name
    41. $33 = {len = 1, data = 0x7fa04800f7fe "/"}
    42. (gdb) print pclcf->static_locations->exact->name
    43. Cannot access memory at address 0x0
    44. (gdb) print pclcf->static_locations->tree->exact->name
    45. Cannot access memory at address 0x0
    46. (gdb) print pclcf->static_locations->tree->inclusive->name
    47. $34 = {len = 5, data = 0x7fa048007a94 "/api/"}
    48. (gdb) print pclcf->static_locations->tree->left->exact->name
    49. $35 = {len = 9, data = 0x7fa048006653 "/50x.html"}
    50. (gdb) print pclcf->static_locations->tree->left->inclusive->name
    51. Cannot access memory at address 0x0
    52. (gdb) print pclcf->static_locations->tree->right->exact->name
    53. $36 = {len = 13, data = 0x7fa048008feb "/exactly.html"}
    54. (gdb) print pclcf->static_locations->tree->right->inclusive->name
    55. $37 = {len = 13, data = 0x7fa04801d8ec "/exactly.html"}

    location = /exactly.html 

    1. Breakpoint 2, ngx_http_core_find_static_location (r=0x7fa049800050,
    2. node=0x7fa048023fa8) at src/http/ngx_http_core_module.c:1509
    3. 1509 if (node->exact) {
    4. (gdb) print node
    5. $38 = (ngx_http_location_tree_node_t *) 0x7fa048023fa8
    6. (gdb) print node->exact->name
    7. $39 = {len = 13, data = 0x7fa048008feb "/exactly.html"}
    8. (gdb) print r.uri
    9. $40 = {len = 13, data = 0x7fa04b800004 "/exactly.html HTTP/1.1\r\nHost"}
    10. (gdb) next
    11. 1510
    12. (gdb) next
    13. 1511
    14. (gdb) next
    15. 1530
    16. (gdb) next
    17. ngx_http_core_find_location (r=0x7fa049800050) at src/http/ngx_http_core_module.c:1393
    18. 1393 if (rc == NGX_AGAIN) {
    19. (gdb) next
    20. 1406 if (rc == NGX_OK || rc == NGX_DONE) {
    21. (gdb) next
    22. 1407 return rc;
    23. (gdb) bt
    24. #0 ngx_http_core_find_location (r=0x7fa049800050)
    25. at src/http/ngx_http_core_module.c:1407
    26. #1 0x0000000107d22f03 in ngx_http_core_find_config_phase (r=0x7fa049800050,
    27. ph=0x7fa048025258) at src/http/ngx_http_core_module.c:953
    28. #2 0x0000000107d22d3e in ngx_http_core_run_phases (r=0x7fa049800050)
    29. at src/http/ngx_http_core_module.c:868
    30. #3 0x0000000107d22cae in ngx_http_handler (r=0x7fa049800050)
    31. at src/http/ngx_http_core_module.c:851
    32. #4 0x0000000107d31f36 in ngx_http_process_request (r=0x7fa049800050)
    33. at src/http/ngx_http_request.c:2060
    34. #5 0x0000000107d3407a in ngx_http_process_request_headers (rev=0x107ee40d0)
    35. at src/http/ngx_http_request.c:1480
    36. #6 0x0000000107d33415 in ngx_http_process_request_line (rev=0x107ee40d0)
    37. at src/http/ngx_http_request.c:1151
    38. #7 0x0000000107d35979 in ngx_http_keepalive_handler (rev=0x107ee40d0)
    39. at src/http/ngx_http_request.c:3333
    40. #8 0x0000000107d1cc10 in ngx_kqueue_process_events (cycle=0x7fa048800c50,
    41. timer=55093, flags=1) at src/event/modules/ngx_kqueue_module.c:669
    42. #9 0x0000000107d0c9f6 in ngx_process_events_and_timers (cycle=0x7fa048800c50)
    43. at src/event/ngx_event.c:247
    44. #10 0x0000000107d1aac5 in ngx_worker_process_cycle (cycle=0x7fa048800c50, data=0x0)
    45. at src/os/unix/ngx_process_cycle.c:750
    46. #11 0x0000000107d17cfa in ngx_spawn_process (cycle=0x7fa048800c50,
    47. proc=0x107d1aa10 <ngx_worker_process_cycle>, data=0x0,
    48. name=0x107de2a1e "worker process", respawn=-3) at src/os/unix/ngx_process.c:199
    49. #12 0x0000000107d19be7 in ngx_start_worker_processes (cycle=0x7fa048800c50, n=1,
    50. type=-3) at src/os/unix/ngx_process_cycle.c:359
    51. #13 0x0000000107d19558 in ngx_master_process_cycle (cycle=0x7fa048800c50)
    52. at src/os/unix/ngx_process_cycle.c:131
    53. #14 0x0000000107cd18ba in main (argc=3, argv=0x7ffee7f2f548) at src/core/nginx.c:382

    location ^~ /api/

    请注意下面 noregex 为 1, 不进行正则匹配 

    1. Breakpoint 3, ngx_http_core_find_static_location (r=0x7fa049804c50,
    2. node=0x7fa048023f10) at src/http/ngx_http_core_module.c:1464
    3. (gdb) print r->uri
    4. $47 = {len = 37,
    5. data = 0x7fa049800004 "/api/HelloWorld/listFormWithoutHeader HTTP/1.1\r\nHost"}
    6. 1464 rv = NGX_DECLINED;
    7. (gdb) next
    8. 1468 if (node == NULL) {
    9. (gdb) next
    10. 1476 n = (len <= (size_t) node->len) ? len : node->len;
    11. (gdb) print node->name
    12. $44 = "/"
    13. (gdb) next
    14. 1478 rc = ngx_filename_cmp(uri, node->name, n);
    15. (gdb) next
    16. 1480 if (rc != 0) {
    17. (gdb) next
    18. 1486 if (len > (size_t) node->len) {
    19. (gdb) next
    20. 1488 if (node->inclusive) {
    21. (gdb) next
    22. 1490 r->loc_conf = node->inclusive->loc_conf;
    23. (gdb) next
    24. 1491 rv = NGX_AGAIN;
    25. (gdb) next
    26. 1493 node = node->tree;
    27. (gdb) next
    28. 1494 uri += n;
    29. (gdb) next
    30. 1495 len -= n;
    31. (gdb) next
    32. 1497 continue;
    33. (gdb) next
    34. 1468 if (node == NULL) {
    35. (gdb) next
    36. 1476 n = (len <= (size_t) node->len) ? len : node->len;
    37. (gdb) print node->name
    38. $45 = "a"
    39. (gdb) next
    40. 1478 rc = ngx_filename_cmp(uri, node->name, n);
    41. (gdb) next
    42. 1480 if (rc != 0) {
    43. (gdb) next
    44. 1486 if (len > (size_t) node->len) {
    45. (gdb) next
    46. 1488 if (node->inclusive) {
    47. (gdb) next
    48. 1490 r->loc_conf = node->inclusive->loc_conf;
    49. (gdb) next
    50. 1491 rv = NGX_AGAIN;
    51. (gdb) next
    52. 1493 node = node->tree;
    53. (gdb) next
    54. 1494 uri += n;
    55. (gdb) next
    56. 1495 len -= n;
    57. (gdb) next
    58. 1497 continue;
    59. (gdb) next
    60. 1468 if (node == NULL) {
    61. (gdb) next
    62. 1469 return rv;
    63. (gdb) next
    64. 1530
    65. (gdb) next
    66. ngx_http_core_find_location (r=0x7fa049804c50) at src/http/ngx_http_core_module.c:1393
    67. 1393 if (rc == NGX_AGAIN) {
    68. (gdb) next
    69. 1396 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
    70. (gdb) next
    71. 1398 noregex = clcf->noregex;
    72. (gdb) next
    73. 1403 rc = ngx_http_core_find_location(r);
    74. (gdb) print noregex
    75. $46 = 1
    76. (gdb) next
    77. Breakpoint 3, ngx_http_core_find_static_location (r=0x7fa049804c50, node=0x0)
    78. at src/http/ngx_http_core_module.c:1464
    79. 1464 rv = NGX_DECLINED;
    80. (gdb) next
    81. 1468 if (node == NULL) {
    82. (gdb) next
    83. 1469 return rv;
    84. (gdb) next
    85. 1530
    86. (gdb) next
    87. ngx_http_core_find_location (r=0x7fa049804c50) at src/http/ngx_http_core_module.c:1393
    88. 1393 if (rc == NGX_AGAIN) {
    89. (gdb) next
    90. 1406 if (rc == NGX_OK || rc == NGX_DONE) {
    91. (gdb) next
    92. 1414 if (noregex == 0 && pclcf->regex_locations) {
    93. (gdb) next
    94. 1442 return rc;
    95. (gdb) bt
    96. #0 ngx_http_core_find_location (r=0x7fa049804c50)
    97. at src/http/ngx_http_core_module.c:1442
    98. #1 0x0000000107d23366 in ngx_http_core_find_location (r=0x7fa049804c50)
    99. at src/http/ngx_http_core_module.c:1403
    100. #2 0x0000000107d22f03 in ngx_http_core_find_config_phase (r=0x7fa049804c50,
    101. ph=0x7fa048025258) at src/http/ngx_http_core_module.c:953
    102. #3 0x0000000107d22d3e in ngx_http_core_run_phases (r=0x7fa049804c50)
    103. at src/http/ngx_http_core_module.c:868
    104. #4 0x0000000107d22cae in ngx_http_handler (r=0x7fa049804c50)
    105. at src/http/ngx_http_core_module.c:851
    106. #5 0x0000000107d31f36 in ngx_http_process_request (r=0x7fa049804c50)
    107. at src/http/ngx_http_request.c:2060
    108. #6 0x0000000107d3407a in ngx_http_process_request_headers (rev=0x107ee40d0)
    109. at src/http/ngx_http_request.c:1480
    110. #7 0x0000000107d33415 in ngx_http_process_request_line (rev=0x107ee40d0)
    111. at src/http/ngx_http_request.c:1151
    112. #8 0x0000000107d3076d in ngx_http_wait_request_handler (rev=0x107ee40d0)
    113. at src/http/ngx_http_request.c:500
    114. #9 0x0000000107d1cc10 in ngx_kqueue_process_events (cycle=0x7fa048800c50,
    115. timer=59999, flags=1) at src/event/modules/ngx_kqueue_module.c:669
    116. #10 0x0000000107d0c9f6 in ngx_process_events_and_timers (cycle=0x7fa048800c50)
    117. at src/event/ngx_event.c:247
    118. #11 0x0000000107d1aac5 in ngx_worker_process_cycle (cycle=0x7fa048800c50, data=0x0)
    119. at src/os/unix/ngx_process_cycle.c:750
    120. #12 0x0000000107d17cfa in ngx_spawn_process (cycle=0x7fa048800c50,
    121. proc=0x107d1aa10 <ngx_worker_process_cycle>, data=0x0,
    122. name=0x107de2a1e "worker process", respawn=-3) at src/os/unix/ngx_process.c:199
    123. #13 0x0000000107d19be7 in ngx_start_worker_processes (cycle=0x7fa048800c50, n=1,
    124. type=-3) at src/os/unix/ngx_process_cycle.c:359
    125. #14 0x0000000107d19558 in ngx_master_process_cycle (cycle=0x7fa048800c50)
    126. at src/os/unix/ngx_process_cycle.c:131
    127. #15 0x0000000107cd18ba in main (argc=3, argv=0x7ffee7f2f548) at src/core/nginx.c:382
    128. (gdb)

    location ~ /regex.* 

    没有 "location =" 或者 "location ^~" 的匹配, 查询正则匹配 

    1. Breakpoint 1, ngx_http_core_find_location (r=0x7fa04800f850)
    2. at src/http/ngx_http_core_module.c:1391
    3. 1391 rc = ngx_http_core_find_static_location(r, pclcf->static_locations);
    4. (gdb) next
    5. 1393 if (rc == NGX_AGAIN) {
    6. (gdb) next
    7. 1406 if (rc == NGX_OK || rc == NGX_DONE) {
    8. (gdb) next
    9. 1414 if (noregex == 0 && pclcf->regex_locations) {
    10. (gdb) next
    11. 1442 return rc;
    12. (gdb) next
    13. 1443 }
    14. (gdb) next
    15. 1406 if (rc == NGX_OK || rc == NGX_DONE) {
    16. (gdb) next
    17. 1414 if (noregex == 0 && pclcf->regex_locations) {
    18. (gdb) next
    19. 1416 for (clcfp = pclcf->regex_locations; *clcfp; clcfp++) {
    20. (gdb) next
    21. 1421 n = ngx_http_regex_exec(r, (*clcfp)->regex, &r->uri);
    22. (gdb) print (*clcfp)->regex
    23. $54 = (ngx_http_regex_t *) 0x7fa048020248
    24. (gdb) print (*clcfp)->regex->pattern
    25. There is no member named pattern.
    26. (gdb) print (*clcfp)->regex->name
    27. $55 = {len = 8, data = 0x7fa04801edcb "/regex.*"}
    28. (gdb) next
    29. 1423 if (n == NGX_OK) {
    30. (gdb) next
    31. 1424 r->loc_conf = (*clcfp)->loc_conf;
    32. (gdb) next
    33. 1428 rc = ngx_http_core_find_location(r);
    34. (gdb) next
    35. Breakpoint 1, ngx_http_core_find_location (r=0x7fa04800f850)
    36. at src/http/ngx_http_core_module.c:1391
    37. 1391 rc = ngx_http_core_find_static_location(r, pclcf->static_locations);
    38. (gdb) next
    39. 1393 if (rc == NGX_AGAIN) {
    40. (gdb) next
    41. 1406 if (rc == NGX_OK || rc == NGX_DONE) {
    42. (gdb) next
    43. 1414 if (noregex == 0 && pclcf->regex_locations) {
    44. (gdb) next
    45. 1442 return rc;
    46. (gdb) next
    47. 1443 }
    48. (gdb) next
    49. 1430 return (rc == NGX_ERROR) ? rc : NGX_OK;

    location ~* /RgxIgnoreCase.*

    没有 "location =" 或者 "location ^~" 的匹配, 查询正则匹配 

    1. Breakpoint 1, ngx_http_core_find_location (r=0x7fa04a004e50)
    2. at src/http/ngx_http_core_module.c:1391
    3. 1391 rc = ngx_http_core_find_static_location(r, pclcf->static_locations);
    4. (gdb) print r->uri
    5. $56 = {len = 21, data = 0x7fa04a000004 "/rgxIGNORECASExx.html HTTP/1.1\r\nHost"}
    6. (gdb) next
    7. 1393 if (rc == NGX_AGAIN) {
    8. (gdb) next
    9. 1396 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
    10. (gdb) next
    11. 1398 noregex = clcf->noregex;
    12. (gdb) next
    13. 1403 rc = ngx_http_core_find_location(r);
    14. (gdb) next
    15. Breakpoint 1, ngx_http_core_find_location (r=0x7fa04a004e50)
    16. at src/http/ngx_http_core_module.c:1391
    17. 1391 rc = ngx_http_core_find_static_location(r, pclcf->static_locations);
    18. (gdb) next
    19. 1393 if (rc == NGX_AGAIN) {
    20. (gdb) next
    21. 1406 if (rc == NGX_OK || rc == NGX_DONE) {
    22. (gdb) next
    23. 1414 if (noregex == 0 && pclcf->regex_locations) {
    24. (gdb) next
    25. 1442 return rc;
    26. (gdb) next
    27. 1443 }
    28. (gdb) next
    29. 1406 if (rc == NGX_OK || rc == NGX_DONE) {
    30. (gdb) next
    31. 1414 if (noregex == 0 && pclcf->regex_locations) {
    32. (gdb) next
    33. 1416 for (clcfp = pclcf->regex_locations; *clcfp; clcfp++) {
    34. (gdb) next
    35. 1421 n = ngx_http_regex_exec(r, (*clcfp)->regex, &r->uri);
    36. (gdb) print (*clcfp)->regex->name
    37. $57 = {len = 8, data = 0x7fa04801edcb "/regex.*"}
    38. (gdb) next
    39. 1423 if (n == NGX_OK) {
    40. (gdb) next
    41. 1433 if (n == NGX_DECLINED) {
    42. (gdb) next
    43. 1434 continue;
    44. (gdb) next
    45. 1416 for (clcfp = pclcf->regex_locations; *clcfp; clcfp++) {
    46. (gdb) next
    47. 1421 n = ngx_http_regex_exec(r, (*clcfp)->regex, &r->uri);
    48. (gdb) print (*clcfp)->regex->name
    49. $58 = {len = 16, data = 0x7fa048020334 "/RgxIgnoreCase.*"}
    50. (gdb) next
    51. 1423 if (n == NGX_OK) {
    52. (gdb) next
    53. 1424 r->loc_conf = (*clcfp)->loc_conf;
    54. (gdb) next
    55. 1428 rc = ngx_http_core_find_location(r);
    56. (gdb) next
    57. Breakpoint 1, ngx_http_core_find_location (r=0x7fa04a004e50)
    58. at src/http/ngx_http_core_module.c:1391
    59. 1391 rc = ngx_http_core_find_static_location(r, pclcf->static_locations);
    60. (gdb) next
    61. 1393 if (rc == NGX_AGAIN) {
    62. (gdb) next
    63. 1406 if (rc == NGX_OK || rc == NGX_DONE) {
    64. (gdb) next
    65. 1414 if (noregex == 0 && pclcf->regex_locations) {
    66. (gdb) next
    67. 1442 return rc;
    68. (gdb) next
    69. 1443 }
    70. (gdb) next
    71. 1430 return (rc == NGX_ERROR) ? rc : NGX_OK;

    location / 

    找到 "location /" 的匹配, 然后尝试 查询正则匹配 

    然后 没有找到 合适的正则匹配 

    最终使用 "location /" 匹配 

    1. Breakpoint 1, ngx_http_core_find_location (r=0x7fa04b004e50)
    2. at src/http/ngx_http_core_module.c:1391
    3. 1391 rc = ngx_http_core_find_static_location(r, pclcf->static_locations);
    4. (gdb) print r->uri
    5. $59 = {len = 11, data = 0x7fa04b000004 "/index.html HTTP/1.1\r\nHost"}
    6. (gdb) enable 3
    7. (gdb) c
    8. Continuing.
    9. Breakpoint 3, ngx_http_core_find_static_location (r=0x7fa04b004e50,
    10. node=0x7fa048023f10) at src/http/ngx_http_core_module.c:1464
    11. 1464 rv = NGX_DECLINED;
    12. (gdb) next
    13. 1468 if (node == NULL) {
    14. (gdb) next
    15. 1476 n = (len <= (size_t) node->len) ? len : node->len;
    16. (gdb) next
    17. 1478 rc = ngx_filename_cmp(uri, node->name, n);
    18. (gdb) next
    19. 1480 if (rc != 0) {
    20. (gdb) next
    21. 1486 if (len > (size_t) node->len) {
    22. (gdb) next
    23. 1488 if (node->inclusive) {
    24. (gdb) next
    25. 1490 r->loc_conf = node->inclusive->loc_conf;
    26. (gdb) next
    27. 1491 rv = NGX_AGAIN;
    28. (gdb) print node->name
    29. $60 = "/"
    30. (gdb) next
    31. 1493 node = node->tree;
    32. (gdb) next
    33. 1494 uri += n;
    34. (gdb) next
    35. 1495 len -= n;
    36. (gdb) next
    37. 1497 continue;
    38. (gdb) next
    39. 1468 if (node == NULL) {
    40. (gdb) next
    41. 1476 n = (len <= (size_t) node->len) ? len : node->len;
    42. (gdb) next
    43. 1478 rc = ngx_filename_cmp(uri, node->name, n);
    44. (gdb) print node->name
    45. $61 = "a"
    46. (gdb) next
    47. 1480 if (rc != 0) {
    48. (gdb) next
    49. 1481 node = (rc < 0) ? node->left : node->right;
    50. (gdb) next
    51. 1483 continue;
    52. (gdb) next
    53. 1468 if (node == NULL) {
    54. (gdb) next
    55. 1476 n = (len <= (size_t) node->len) ? len : node->len;
    56. (gdb) next
    57. 1478 rc = ngx_filename_cmp(uri, node->name, n);
    58. (gdb) print node->name
    59. $62 = "e"
    60. (gdb) next
    61. 1480 if (rc != 0) {
    62. (gdb) next
    63. 1481 node = (rc < 0) ? node->left : node->right;
    64. (gdb) next
    65. 1483 continue;
    66. (gdb) next
    67. 1468 if (node == NULL) {
    68. (gdb) next
    69. 1469 return rv;
    70. (gdb) next
    71. 1530
    72. (gdb) next
    73. ngx_http_core_find_location (r=0x7fa04b004e50) at src/http/ngx_http_core_module.c:1393
    74. 1393 if (rc == NGX_AGAIN) {
    75. (gdb) next
    76. 1396 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
    77. (gdb) next
    78. 1398 noregex = clcf->noregex;
    79. (gdb) next
    80. 1403 rc = ngx_http_core_find_location(r);
    81. (gdb) next
    82. Breakpoint 1, ngx_http_core_find_location (r=0x7fa04b004e50)
    83. at src/http/ngx_http_core_module.c:1391
    84. 1391 rc = ngx_http_core_find_static_location(r, pclcf->static_locations);
    85. (gdb) next
    86. Breakpoint 3, ngx_http_core_find_static_location (r=0x7fa04b004e50, node=0x0)
    87. at src/http/ngx_http_core_module.c:1464
    88. 1464 rv = NGX_DECLINED;
    89. (gdb) next
    90. 1468 if (node == NULL) {
    91. (gdb) next
    92. 1469 return rv;
    93. (gdb) next
    94. 1530
    95. (gdb) next
    96. ngx_http_core_find_location (r=0x7fa04b004e50) at src/http/ngx_http_core_module.c:1393
    97. 1393 if (rc == NGX_AGAIN) {
    98. (gdb) next
    99. 1406 if (rc == NGX_OK || rc == NGX_DONE) {
    100. (gdb) next
    101. 1414 if (noregex == 0 && pclcf->regex_locations) {
    102. (gdb) print noregex
    103. $63 = 0
    104. (gdb) next
    105. 1442 return rc;
    106. (gdb) next
    107. 1443 }
    108. (gdb) next
    109. 1406 if (rc == NGX_OK || rc == NGX_DONE) {
    110. (gdb) next
    111. 1414 if (noregex == 0 && pclcf->regex_locations) {
    112. (gdb) next
    113. 1416 for (clcfp = pclcf->regex_locations; *clcfp; clcfp++) {
    114. (gdb) next
    115. 1421 n = ngx_http_regex_exec(r, (*clcfp)->regex, &r->uri);
    116. (gdb) print (*clcfp)->regex->name
    117. $64 = {len = 8, data = 0x7fa04801edcb "/regex.*"}
    118. (gdb) next
    119. 1423 if (n == NGX_OK) {
    120. (gdb) next
    121. 1433 if (n == NGX_DECLINED) {
    122. (gdb) next
    123. 1434 continue;
    124. (gdb) next
    125. 1416 for (clcfp = pclcf->regex_locations; *clcfp; clcfp++) {
    126. (gdb) next
    127. 1421 n = ngx_http_regex_exec(r, (*clcfp)->regex, &r->uri);
    128. (gdb) (*clcfp)->regex
    129. Undefined command: "". Try "help".
    130. (gdb) print (*clcfp)->regex->name
    131. $65 = {len = 16, data = 0x7fa048020334 "/RgxIgnoreCase.*"}
    132. (gdb) next
    133. 1423 if (n == NGX_OK) {
    134. (gdb) next
    135. 1433 if (n == NGX_DECLINED) {
    136. (gdb) next
    137. 1434 continue;
    138. (gdb) next
    139. 1416 for (clcfp = pclcf->regex_locations; *clcfp; clcfp++) {
    140. (gdb) next
    141. 1439 }
    142. (gdb) next
    143. 1442 return rc;
    144. (gdb) print ((ngx_http_core_loc_conf_t *)r->loc_conf[0])->name
    145. $66 = {len = 1, data = 0x7fa04800f7fe "/"}
    146. (gdb) print rc
    147. $67 = -5

  • 相关阅读:
    java-websocket连接多个websocket server 自定义springboot
    图像处理算法实战【2】读取图片并获取指定像素位置的RGB值
    Slipper —— 虚点,最短路
    java计算机毕业设计基于springboot+vue+elementUI的旅游网站(源码+数据库+Lw文档)
    【深度学习笔记】计算机视觉——单发多框检测(SSD)
    Mybatis面试总结(1)
    剑指Offer || 050.路径总和|||
    Vue—大文件分片上传
    区块链是如何演化的?
    数字全息干涉重建算法研究
  • 原文地址:https://blog.csdn.net/u011039332/article/details/125467695