{"record":{"id":"a39397ce484b6f5c","repo":"lionsoul2014/ip2region","slug":"failed-to-create-searcher-s","errorCode":null,"errorMessage":"failed to create searcher: %s","messagePattern":"failed to create searcher: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"binding/nginx/src/ngx_http_ip2region_module.c","lineNumber":156,"sourceCode":"    }\n\n    // 验证XDB文件版本是否匹配\n    if (xdb_version->id != expected_version->id) {\n        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n                           \"%s expects %s xdb file, but got %s: %s\",\n                           directive_name, expected_version->name, xdb_version->name, db_path);\n        xdb_free_header((void *)header);\n        if(ngx_http_ip2region_is_absolute_path(db_name) != NGX_OK) {\n            free(db_path);\n        }\n        return NGX_CONF_ERROR;\n    }\n\n    if (strcmp(cache_policy, \"file\") == 0) {\n        err = xdb_new_with_file_only(xdb_version, &ip2region_searcher->searcher, db_path);\n        xdb_free_header((void *)header);\n        if (err != 0) {\n            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n                               \"failed to create searcher: %s\", db_path);\n            if(ngx_http_ip2region_is_absolute_path(db_name) != NGX_OK) {\n                free(db_path);\n            }\n            return NGX_CONF_ERROR;\n        }\n    } else if (strcmp(cache_policy, \"vectorIndex\") == 0) {\n        ip2region_searcher->v_index = xdb_load_vector_index_from_file(db_path);\n        if (ip2region_searcher->v_index == NULL) {\n            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n                               \"failed to load vector index from: %s\", db_path);\n            xdb_free_header((void *)header);\n            if(ngx_http_ip2region_is_absolute_path(db_name) != NGX_OK) {\n                free(db_path);\n            }\n            return NGX_CONF_ERROR;\n        }\n","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/lionsoul2014/ip2region/blob/c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1/binding/nginx/src/ngx_http_ip2region_module.c#L138-L174","documentation":"With cache_policy \"file\", the module creates a searcher that reads the xdb directly from disk via xdb_new_with_file_only. A non-zero return means the searcher could not be created — almost always because the file cannot be opened/read at runtime by the nginx worker/master user.","triggerScenarios":"xdb_new_with_file_only returns != 0: file path does not exist at that absolute path, permission denied for the nginx user, or an invalid xdb handle/path passed after the earlier checks passed.","commonSituations":"Relative path resolving against an unexpected working directory for worker processes; file readable by root but not by the nginx worker user (www-data/nginx); SELinux/AppArmor blocking read; file moved after config was validated.","solutions":["Verify the absolute path exists and is readable: `sudo -u www-data cat /path/to/ip2region.xdb >/dev/null`.","chmod/chown the xdb so the nginx worker user can read it (e.g. chmod 644).","Use an absolute path in the ip2region_cache_policy file setup to avoid cwd ambiguity.","Check audit logs for SELinux/AppArmor denials and allow the read.","Re-test with a freshly downloaded xdb to rule out file corruption."],"exampleFix":"# before\nip2region_db_file data/ip2region.xdb;\n# after\nip2region_db_file /usr/share/ip2region/ip2region.xdb;\n# and ensure: chmod 644 /usr/share/ip2region/ip2region.xdb","handlingStrategy":"validation","validationCode":"#!/bin/bash\nf=$(awk '/ip2region_db_file /{print $2; exit}' /etc/nginx/nginx.conf | tr -d ';')\nsudo -u www-data test -r \"$f\" && echo OK || echo \"nginx user cannot read $f\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use absolute paths in ip2region_db_file.","chmod 644 the xdb and ensure the nginx worker user (www-data/nginx) can read it.","Check SELinux/AppArmor policies for the data directory.","Re-check readability after every data refresh."],"tags":["nginx","file-io","permissions","xdb","config-startup"],"backgroundTag":"xdb-file-not-readable","analyzedSha":"c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1","analyzedAt":"2026-09-02T16:58:39.988Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}