load_module指令必须置于nginx.conf最顶部(events和http块之前),仅支持动态模块.so文件,路径须绝对或相对于配置文件,且需版本与ABI严格匹配。
在 Nginx 的 nginx.conf 中引用第三方模块,核心只有一条指令:load_module,且必须放在配置文件最顶部(events 或 http 块之前),不能嵌套在任何块内。
该指令用于加载已编译好的动态模块(.so 文件),语法严格、位置敏感:
load_module,不可用分号或逗号合并多个--prefix)的相对路径,例如:load_module modules/ngx_http_geoip2_module.so;
load_module /usr/lib64/nginx/modules/ngx_http_headers_more_filter_module.so;
events、http 等任何配置块之前;若写在 http 块内部,Nginx 启动时会报错并拒绝加载仅写 load_module 不代表功能可用,还需在后续配置中显式启用模块提供的指令或功能:
headers-more-nginx-module,需在 server 或 location 块中使用 more_set_headers 等指令ngx_http_geoip2_module,需在 http 块中配置 geoip2 指令指向数据库文件配置修改后不能直接重启,需先验证再重载:
nginx -t:提示 configuration file /etc/nginx/nginx.conf test is successful 表示语法正确nginx -s reload 重载配置tail -f /var/log/nginx/error.log,无 module "xxx" is not binary compatible 或 undefined symbol 报错即为成功nginx -V 2>&1 | grep 'modules/.*.so' 可列出当前加载的动态模块路径很多配置失败源于对机制理解偏差:
load_module 仅支持动态模块(.so),不适用于静态编译进 Nginx 的模块(那些出现在 nginx -V 输出中的 --with-xxx)undefined symbol