{"record":{"id":"b72d82588721e79f","repo":"lionsoul2014/ip2region","slug":"s-expects-s-xdb-file-but-got-s-s","errorCode":null,"errorMessage":"%s expects %s xdb file, but got %s: %s","messagePattern":"(.+?) expects (.+?) xdb file, but got (.+?): (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"binding/nginx/src/ngx_http_ip2region_module.c","lineNumber":142,"sourceCode":"            free(db_path);\n        }\n        return NGX_CONF_ERROR;\n    }\n\n    xdb_version_t *xdb_version = xdb_version_from_header(header);\n    if (xdb_version == NULL) {\n        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n                           \"failed to determine xdb version from header: %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\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            }","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/lionsoul2014/ip2region/blob/c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1/binding/nginx/src/ngx_http_ip2region_module.c#L124-L160","documentation":"The xdb header was parsed successfully, but its version does not match the version expected by the directive used: ip2region_db_file expects the IPv4-format xdb and ip2region_db_file_v6 expects the IPv6-format xdb. The module compares xdb_version->id with expected_version->id and aborts configuration when they differ.","triggerScenarios":"Using `ip2region_db_file` with an IPv6-region xdb file, or `ip2region_db_file_v6` with an IPv4-region xdb file; also mixing data files from different ip2region generations (e.g. v2 xdb with a v3-expecting directive).","commonSituations":"Upgrading ip2region and keeping an old data file; copying the v4 xdb path into the v6 directive (or vice versa) in nginx.conf; having both ip2region_v4.xdb and ip2region_v6.xdb and wiring them swapped.","solutions":["Match the directive to the file: use ip2region_db_file for the IPv4 xdb and ip2region_db_file_v6 for the IPv6 xdb.","Swap the two file paths in nginx.conf if they are crossed.","Re-download the correct-region xdb (ip2region v4 or v6 data) matching your module build.","Check the logged expected vs got version names to confirm which file to replace."],"exampleFix":"# before\nip2region_db_file /data/ip2region_v6.xdb;\n# after\nip2region_db_file /data/ip2region_v4.xdb;\nip2region_db_file_v6 /data/ip2region_v6.xdb;","handlingStrategy":"validation","validationCode":"#!/bin/bash\n# pair each directive with the right file: name files by region and assert\nv4=/data/ip2region_v4.xdb; v6=/data/ip2region_v6.xdb\ngrep -E 'ip2region_db_file(\\s|;)' nginx.conf | grep -q \"$v4\" || echo \"WARN: ip2region_db_file should point to the v4 xdb\"\ngrep -q \"ip2region_db_file_v6.*$v6\" nginx.conf || echo \"WARN: ip2region_db_file_v6 should point to the v6 xdb\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Name data files with their region suffix (v4/v6) and wire them 1:1 to the matching directives.","After upgrading the module, replace both data files together from the same release.","Use `nginx -t` before every reload.","Read the 'expects X, got Y' message literally — swap the paths."],"tags":["nginx","xdb","version-mismatch","config-startup","ipv6"],"backgroundTag":"xdb-version-mismatch","analyzedSha":"c1a1fc7d5941760db3f8431dc05c48cf7f0e30a1","analyzedAt":"2026-09-02T16:58:39.988Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}