如何在现有的NGINX安装中启用动态模块 [英] How to enable dynamic module with an existing NGINX installation

查看:139
本文介绍了如何在现有的NGINX安装中启用动态模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从NGINX版本1.9.11及更高版本开始,引入了一项新功能:动态模块.

使用动态模块,您可以选择在运行时将单独的共享库文件作为模块加载-第三方模块和某些本机NGINX模块. ()

From NGINX version 1.9.11 and upwarts, a new feature is introduced: dynamic modules.

With dynamic modules, you can optionally load separate shared object files at runtime as modules – both third-party modules and some native NGINX modules. (source)

我从主线(当前为1.9.14)安装了NGINX,因此它能够使用动态模块.它还具有我要动态启用的模块:

I have NGINX installed from the mainline (currently 1.9.14) so it is capable to use dynamic modules. It has also the module I want dynamicly enabled:

nginx -V
nginx version: nginx/1.9.14
built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.1) 
built with OpenSSL 1.0.1f 6 Jan 2014
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules ... --with-http_geoip_module=dynamic ...

请注意--with-http_geoip_module=dynamic,它会(动态)加载我需要的模块. 不幸的是,缺少文档(一些详细信息),因此我无法进行设置.
我已经安装了NGINX(不是来自源代码).但是据我了解,我只需要构建模块,将生成的模块文件放在正确的NGINX文件夹中,然后在配置文件中启用它即可.

Note the --with-http_geoip_module=dynamic which loads the module I need (dynamically). Unfortunately, the documentation is lacking (some details) and I am unable to set this up.
I have an existing NGINX installation (not from source). But so far as I can understand I just need to build the module, place the generated module file in the right NGINX folder and enable it in the config file.

我在另一台机器(具有相同配置,但没有生产机器)上对此进行了测试,但是没有看到ngx_http_geoip_module.so文件. 我使用的命令:

I tested this on a different machine (with the same configuration, but not a production machine), but I don't see the ngx_http_geoip_module.so file. The commands I used:

wget http://nginx.org/download/nginx-1.9.14.tar.gz
tar -xzf nginx-1.9.14.tar.gz
cd nginx-1.9.14/
./configure --with-http_geoip_module=dynamic

问题

  • 我尝试在具有以下功能的系统上构建模块是一个问题吗? NGINX是否从源安装了不是?
  • 为什么我的命令没有生成.so文件?
  • The questions

    • Is it a problem that I try to build the module on a system that has NGINX installed not from source?
    • Why is there no .so file generated by my commands?
    • 推荐答案

      我有同样的问题,@ vladiastudillo的答案是我需要的缺失部分.

      I had the same question, and @vladiastudillo answer was the missing piece I needed.

      首先添加nginx稳定仓库:

      First add the nginx stable repo:

      sudo add-apt-repository ppa:nginx/stable
      

      然后运行apt更新:

      sudo apt-get update
      

      并获取nginx geoip模块:

      And get the nginx geoip module:

      sudo apt-get install nginx-module-geoip
      

      这会将模块下载并加载到/usr/lib/nginx/modules

      This will download and load the module to /usr/lib/nginx/modules

      要加载nginx模块,

      To load the nginx module,

      打开nginx.conf:

      sudo nano /etc/nginx/nginx.conf
      

      add在主上下文中添加以下内容:

      add add below in the main context:

      load_module "modules/ngx_http_geoip_module.so";
      

      当您重新加载配置或重新启动nginx时,模块将被加载.

      The module will be loaded, when you reload the configuration or restart nginx.

      要动态卸载"模块,请注释掉或删除其load_module指令,然后重新加载nginx配置.

      To dynamically "unload" a module, comment out or remove its load_module directive and reload the nginx configuration.

      这篇关于如何在现有的NGINX安装中启用动态模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆