Nginx添加模块
编译安装Nginx的时候,有些模块默认不会安装,比如http_ssl_module
。那么为了让Nginx支持HTTPS,必须添加这个模块。下面讲解如何在已经安装过后在此添加新的模块。
支持功能 |
所需模块 |
https |
http_ssl_module |
fastdfs |
ngx_fastdfs_module |
gzip |
http_gzip_static_module |
监控 |
http_stub_status_module |
1. 进入Nginx源码根目录
即最初的安装包目录,如果没有的话,下载新的源码并解压即可。
1
| [root@localhost ~]# cd /data/portal/nginx
|
2. 查看nginx版本及其编译参数
1
| [root@localhost ~]# /usr/local/nginx/sbin/nginx -V
|
3. 重新编译代码和模块
1
| [root@localhost nginx]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module
|
4. 执行make
(注意:千万别 make install ,否则就覆盖安装了), make完之后在/data/portal/nginx/nginx-1.6.2/objs/
目录下就多了个nginx,这个就是新版本的程序了。
1
| [root@localhost nginx]# make
|

5. 备份旧的nginx程序
1 2
| [root@localhost ~]# cd /usr/local/nginx/sbin [root@localhost sbin]#mv nginx nginx_bak
|
6. 把新的nginx程序复制至/usr/local/nginx/sbin
1
| [root@localhost ~]# cp /data/portal/nginx/nginx-1.6.2/objs/nginx /usr/local/nginx/sbin/
|
7. 检测程序是否正确
1
| [root@localhost ~]#/usr/local/nginx/sbin/nginx -t
|

8. 平滑启动服务
1
| [root@localhost ~]#/usr/local/nginx/sbin/nginx -s reload
|
9. 查看模块是否安装
1
| [root@localhost ~]# /usr/local/nginx/sbin/nginx -V
|

10. 重启nginx
Nginx重新安装模块后,必须先退出,然后再次启动,该模块才会生效。
1 2
| [root@localhost ~]# /usr/local/nginx/sbin/nginx -s quit [root@localhost ~]# /usr/local/nginx/sbin/nginx
|