在nginx module开发中,有时会遇到类型未定义、类型不完整(has incomplete type)等编译错误,这是因为头文件包含顺序不正确造成的。

根据nginx官网的指导:

以下两个文件必须包含在所有nginx文件的最顶部 The following two ​​#include​​ statements must appear at the beginning of every nginx file:

#include <ngx_config.h>

#include <ngx_core.h>

此外,HTTP代码应包含 In addition to that, HTTP code should include

#include <ngx_http.h>

Mail代码应包含 Mail code should include

#include <ngx_mail.h>

Stream代码应包含 Stream code should include

#include <ngx_stream.h>