nginx安装成功后,发现有一些其他模块没有编译进去,或者想额外添加一些模块,这时候就要重新编译nginx。

首先,查看之前编译的一些参数,比如:

1
2
3
4
5
[root@lmode nginx]# /usr/local/nginx/nginx -V
nginx version: nginx/1.4.7
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) 
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=www --group=www --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-pcre=/usr/local/src/lnmp/pcre-8.33 --with-zlib=/usr/local/src/lnmp/zlib-1.2.8 --with-openssl=/usr/local/src/lnmp/openssl-1.0.1e 

比如我现在要新增–with-http_ssl_module 、–with-http_gzip_static_module 这些模块参数,那么我只要把这些参数添加进去然后重新编译即可,需要注意的是原先编译过的参数也要加进来。过程如下:

进入nginx源码包

1
[root@lmode nginx]# cd /usr/local/src/nginx-1.4.7

将要编译的参数重新添加到后面

1
[root@lmode nginx-1.4.7]# ./configure --prefix=/usr/local/nginx --user=www --group=www --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid  --with-pcre=/usr/local/src/lnmp/pcre-8.33 --with-zlib=/usr/local/src/lnmp/zlib-1.2.8 --with-openssl=/usr/local/src/lnmp/openssl-1.0.1e --with-http_gzip_static_module --with-http_ssl_module

注意:这里只能make 千万别make install,否则就覆盖安装了

1
[root@lmode nginx-1.4.7]# make

make完成后,在源码目录下会有一个objs目录,objs目录下就多了个nginx,这个就是新版本的程序了。

1
2
3
[root@lmode nginx-1.4.7]# ls
 
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src

然后将objs目录下的nginx替换之前已经安装过的nginx。

先备份旧的nginx程序

1
[root@lmode nginx-1.4.7]#cp /usr/local/nginx/nginx  /usr/local/nginx/nginx.bak

把新的nginx程序覆盖旧的

1
[root@lmode nginx-1.4.7]#cp ./objs/nginx /usr/local/nginx/sbin/nginx

如果提示“cp:cannot create regular file `/usr/local/nginx/sbin/nginx': Text file busy”

建议使用如下语句cp

1
#cp -rfp objs/nginx /usr/local/nginx/sbin/nginx

测试新的nginx程序是否正确

1
2
3
[root@lmode nginx-1.4.7]# /usr/local/nginx/nginx -t
nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/nginx.conf test is successful

最后重启nginx

1
[root@lmode nginx-1.4.7]# /usr/local/nginx/nginx -s reload

这样,就安装成功了。下面介绍下安装第三方模块的方法。

安装第三方模块

nginx安装第三方模块的方法和上面差不多,只是要额外添加一个–add-module参数:

1
./configure --prefix=/你的安装目录  --add-module=/第三方模块目录

下面以安装pagespeed模块位实例

1
2
3
4
5
6
7
# ./configure --prefix=--prefix=/usr/local/nginx --user=www --group=www --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid  --with-pcre=/usr/local/src/lnmp/pcre-8.33 --with-zlib=/usr/local/src/lnmp/zlib-1.2.8 --with-openssl=/usr/local/src/lnmp/openssl-1.0.1e --with-http_gzip_static_module --with-http_ssl_module --add-module=../ngx_pagespeed-master
 
# make
 
# cp ./objs/nginx /usr/local/nginx/nginx
 
# /usr/local/nginx/nginx -s reload

总结

安装nginx安装第三方模块实际上是使用–add-module重新安装一次nginx,不要make install而是直接把编译目录下objs/nginx文件直接覆盖老的nginx文件.如果你需要安装多个nginx第三方模块,你只需要多指定几个相应的–add-module即可。

[warning]备注:重新编译的时候,记得一定要把以前编译过的模块一同加到configure参数里。

关于nginx重新编译的更多相关文章

  1. Nginx 的编译安装和URL地址重写

    本文转自:http://www.178linux.com/14119#rd?sukey=ecafc0a7cc4a741b573a095a3eb78af6b4c9116b74d0bbc9844d8fc5 ...

  2. CentOS6.5 Nginx优化编译配置[续]

    继续上文CentOS6.5 Nginx优化编译配置本文记录有关Nginx系统环境的一些细节设置,有关Nginx性能调整除了配置文件吻合服务器硬件之前就是关闭不必要的服务.磁盘操作.文件描述符.内核调整 ...

  3. nginx应用编译安装

    nginx应用编译安装: 安装编译所需依赖包: # apt-get install make gcc g++ libcurl3-openssl-dev libfreetype6-dev libmcry ...

  4. nginx的编译安装以及启动脚本编写

    Nginx的编译安装和启动脚本的编写 Nginxd的功能强大,可以实现代理.负载均衡等企业常用的功能.下面介绍一下nginx的编译安装方法: 1. 下载 官方下载地址:http://nginx.org ...

  5. 初识Nginx及编译安装Nginx

    初识Nginx及编译安装Nginx 环境说明: 系统版本    CentOS 6.9 x86_64 软件版本    nginx-1.12.2 1.什么是Nginx? 如果你听说或使用过Apache软件 ...

  6. (转载)学校搭建使用nginx同时编译rtmp-module进行直播的技术文档

    原文地址:学校搭建使用 nginx 同时编译 rtmp-module 进行直播的技术文档 转载自我的大佬同学 MetalkgLZH.学校有几次需要全校观看网络直播的情况,但是学校的带宽不允许所有的班一 ...

  7. 【01】Nginx:编译安装/动态添加模块

    写在前面的话 说起 Nginx,别说运维,就是很多开发人员也很熟悉,毕竟如今已经 2019 年了,Apache 更多的要么成为了历史,要么成为了历史残留. 我们在提及 Nginx 的时候,一直在强调他 ...

  8. nginx重新编译不停服

    找到安装nginx的源码根目录,如果没有就下载新的安装包 .tar.gz 查看ngixn版本极其编译参数 /usr/local/nginx/sbin/nginx -V 进入nginx源码目录 cd n ...

  9. nginx重新编译安装upload模块

    由于php处理上传会出现超时,并且显示上传进度官方php不支持nginx+php,所以决定让nginx自己处理上传,我本地环境是mac上已经安装过nginx1.8.0,安装方式为brew,所以需要重新 ...

  10. 已经编译安装的nginx/tenginx编译增加新模块

    只适用于自行编译安装的nginx配置 业务变更带来的Nginx增加模块需求 由于业务从php转为go开发,需要用到Http2的协议.这种协议在Nginx上需要http_v2_module这个模块的支持 ...

随机推荐

  1. KVM上如何让虚拟机支持虚拟化(kvm虚拟化的嵌套)

    http://blog.csdn.net/swimming_in_it_/article/details/53320141http://blog.csdn.net/wickedglory/articl ...

  2. 物联网架构成长之路(10)-Nginx负载均衡

    0. 前言 关于Nginx负载均衡的简单配置,我以前博客配置过基于HTTP的负载均衡.这次的负载均衡有点不一样,就是基于TCP的负载均衡.基于HTTP负载均衡是默认的Nginx版本支持的,配置也很简单 ...

  3. packetfence 7.2网络准入部署(二)

    今天呢先说下packetfence部署的环境: 关于使用方法之前的帖子有介绍,一定要看哦 https://blog.csdn.net/qq_18204953/article/details/80708 ...

  4. Oralce 日期操作

    1.日期比较 --1.在确定时间之前: select * from up_date where update < to_date('2018-06-05 00:00:00','yyyy-mm-d ...

  5. Kylin 与 Spark SQL相比,有哪些差异和优势?

    SparkSQL本质上是基于DAG模型的MPP.而Kylin核心是Cube(多维立方体).关于MPP和Cube预处理的差异,重复如下: > MPP [1] 的基本思路是增加机器来并行计算,从而提 ...

  6. linux下yum安装最新稳定版nginx

    ## 摘抄nginx官网文档 URL:http://nginx.org/en/linux_packages.html#stable To set up the yum repository for R ...

  7. ubuntu将GNU nano换成vim

    ubuntu默认编辑器为gnu nano,使用方法是ctrl+字母键 但是gnu nano没有vim好用,我们把它切换到vim 在终端下输入以下命令 sudo update-alternatives ...

  8. Java知多少(49)throw:异常的抛出

    到目前为止,你只是获取了被Java运行时系统抛出的异常.然而,程序可以用throw语句抛出明确的异常.Throw语句的通常形式如下:    throw ThrowableInstance;这里,Thr ...

  9. 错误:OSError: [Errno 1] Operation not permitted: 'lib/python/six-1.4.1-py2.7.egg-info'

    解决办法: $ $ pip install mock --ignore-installed six --user 问题:安装mock时报错: (venv)➜ test git:(master) pip ...

  10. 正确释放WORD对象(COM组件) COMException: 被调用的对象已与其客户端断开连接

    本来form method=post本页面 修改为其他页面 action=save.aspx后没问题 其他问题可参考以下: 引自:http://topic.csdn.net/u/20090108/17 ...