首页 > 解决方案 > NginX GeoIP 模块配置 - Conf 的第一行不允许 load_module

问题描述

我的 nginx 配置文件如下所示:

include /usr/share/nginx/modules/mod-http-geoip.conf;

server {

}

server {

}

我已经通过 sudo yum install nginx-mod-http-geoip 安装了 mod-http-geoip

我有这些:

/usr/share/nginx/modules/mod-http-geoip.conf:

load_module "/usr/lib64/nginx/modules/ngx_http_geoip_module.so";

/usr/lib64/nginx/modules/ngx_http_geoip_module.so

我得到的错误:

2018/07/09 09:37:14 [emerg] 9552#0:/usr/share/nginx/modules/mod-http-geoip.conf:1 中不允许使用“load_module”指令

这是我的 nginx -V :

[root@ip-172-31-45-46 modules]# nginx -V
nginx version: nginx/1.12.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --with-ld-opt=' -Wl,-E'

请注意,上面有“--with-http_geoip_module=dynamic”参数

有人可以指出我缺少什么吗?

我在这篇文章中关注了 Peter Jones 的回答:How to enable dynamic module with an existing NGINX installation

我也试过: - 把 load_module "/usr/lib64/nginx/modules/ngx_http_geoip_module.so"; 在我的 .conf 文件的第一行。- 将加载模块“/usr/lib64/nginx/modules/ngx_http_geoip_module.so”;在服务器内 { }

都给了我同样的错误,这里不允许使用“load_module”指令

我是否需要运行 ./configure 命令、make 或其他任何东西?

标签: nginxgeoipnginx-config

解决方案


根据到目前为止的所有信息,您已经从 EPEL 存储库安装了 nginx。虽然这没有什么问题,但我建议从 nginx 自己的 YUM 存储库安装它,因为它是:

  • 来自软件开发商
  • 最近(我现在看到 nginx 自己的 repo 是 1.14.0 而 epel 是 1.12.2)

因此,请确保正确安装 nginx

每个 nginx 发行版都倾向于有自己的结构化文件约定。但是nginx的配置规则是一样的。所以:

include /usr/share/nginx/modules/mod-http-geoip.conf;
server {

}
server {

}

... 是不可能的,因为server块应该在http部分内。

应该load_module放在./etc/nginx/nginx.conf

如果你不能离开 / 想坚持使用 EPEL 的 nginx 发行版

EPEL nginx 包约定是从每个模块的文件中包含这些load_module指令:.conf

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

安装模块后,它会删除一个 .conf 文件load_module来加载它。

确保它include位于 nginx 配置的顶部,而不是任何部分。


推荐阅读