系统环境:
[root@GaoServer ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@GaoServer ~]# uname -r 3.10.0-327.el7.x86_64 [root@GaoServer ~]# uname -o GNU/Linu
官方文档定义:http://nginx.org/en/docs/ngx_core_module.html#directives
加载动态模块:
Syntax: | load_module |
---|---|
Default: | — |
Context: | main |
This directive appeared in version 1.9.11.
###-->1.9.11中出现,其中Context:main,只能在main字段(全局配置段)中使用;
Loads a dynamic module.
Example:
load_module modules/ngx_mail_module.so;
软件/程序包版本:
#版本需要匹配 [root@GaoServer ~]# nginx -V nginx version: nginx/1.10.2 ...... [root@GaoServer ~]# ls | grep module nginx-module-geoip-1.10.2-1.el7.ngx.x86_64.rpm
安装RPM:
#查看其中包含的文件.so结尾 [root@GaoServer ~]# rpm -qpl nginx-module-geoip-1.10.2-1.el7.ngx.x86_64.rpm /usr/lib64/nginx/modules/ngx_http_geoip_module-debug.so /usr/lib64/nginx/modules/ngx_http_geoip_module.so #相关模块信息,安装路径 /usr/share/doc/nginx-module-geoip /usr/share/doc/nginx-module-geoip/COPYRIGHT [root@GaoServer ~]# yum install ./nginx-module-geoip-1.10.2-1.el7.ngx.x86_64.rpm -y ...... 已安装: nginx-module-geoip.x86_64 1:1.10.2-1.el7.ngx 作为依赖被安装: GeoIP.x86_64 0:1.5.0-9.el7
查看模块:
#链接文件,默认安装至/usr/lib64/nginx...... [root@GaoServer nginx]# ll | grep modules lrwxrwxrwx 1 root root 29 9月 9 23:40 modules -> ../../usr/lib64/nginx/modules [root@GaoServer ~]# ls /usr/lib64/nginx/modules/ ngx_http_geoip_module-debug.so ngx_http_geoip_module.so [root@GaoServer ~]# ls /etc/nginx/modules/ ngx_http_geoip_module-debug.so ngx_http_geoip_module.so
装载模块:
#装载指令load_module modules/ngx_http_geoip_module.so; [root@GaoServer nginx]# vim /etc/nginx/nginx.conf user nginx; worker_processes 2; load_module modules/ngx_http_geoip_module.so; ...... #写入退出 [root@GaoServer nginx]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@GaoServer nginx]# nginx -s reload #测试配置文件是否正确,重新加载即可生效
本文出自 “Gning丶” 博客,请务必保留此出处http://gning.blog.51cto.com/11847592/1964156
原文地址:http://gning.blog.51cto.com/11847592/1964156