• 关于nginx重新编译


    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参数里。

  • 相关阅读:
    Unity Find 使用规则
    Unity UGUI
    Unity UGUI
    Unity UGUI
    Unity UGUI
    机器学习:支持向量机识别手写英文字母 SMO算法实现二元分类器
    机器学习:朴素贝叶斯分类器实现二分类(伯努利型) 代码+项目实战
    机器学习:基于CART算法的决策树——分类树与回归树
    机器学习:决策树——分类树 ID3算法 代码+案例
    JAVA
  • 原文地址:https://www.cnblogs.com/zhengchunyuan/p/9430082.html
Copyright © 2020-2023  润新知