美文网首页工作生活
Linux(centos 7.2)下nginx安装步骤(SSL搭

Linux(centos 7.2)下nginx安装步骤(SSL搭

作者: kf_0169 | 来源:发表于2019-06-30 22:23 被阅读0次

    前面四步可以看自己本机情况安装

    1、gcc安装

    查看是否有gcc
    gcc -v
    没有需要安装gcc,执行以下命令
    yum -y install gcc gcc-c++ autoconf pcre pcre-devel make automake
    yum -y install wget httpd-tools vim
    查看gcc -v 若报 comand not found,再执行
    yum -y install gcc automake autoconf libtool make
    cc -v查看能看到版本
    gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)

    2、PCRE库安装

    yum install pcre pcre-devel

    3、zlib库安装

    yum install zlib zlib-devel

    4、OpenSSL库安装

    yum install openssl openssl-devel

    另外上述几个库安装过程中,可能报如下错误

    Error: Multilib version problems found. This often means that the root 
    cause is something else and multilib version checking is just 
    pointing out that there is a problem. Eg.:
         1. You have an upgrade for zlib which is missing some
            dependency that another package requires. Yum is trying to
            solve this by installing an older version of zlib of the
            different architecture. If you exclude the bad architecture
            yum will tell you what the root cause is (which package
            requires what). You can try redoing the upgrade with
            --exclude zlib.otherarch ... this should give you an error
            message showing the root cause of the problem.
    
         2. You have multiple architectures of zlib installed, but
            yum can only see an upgrade for one of those architectures.
            If you don't want/need both architectures anymore then you
            can remove the one with the missing update and everything
            will work.
    
         3. You have duplicate versions of zlib installed already.
            You can use "yum check" to get yum show these errors.
    
       ...you can also use --setopt=protected_multilib=false to remove
       this checking, however this is almost never the correct thing to
       do as something else is very likely to go wrong (often causing
       much more problems).
    

    上述常见原因是有两个版本的库。

    用以下命令查看zlib库:
    [root@VM_0_14_centos ~]# rpm -qa | grep zlib
    zlib-1.2.7-15.el7.i686
    zlib-1.2.7-15.el7.x86_64
    然后用以下命令删除其中一个版本
    [root@VM_0_14_centos ~]# yum erase zlib-1.2.7-15.el7.i686

    假设你上述库都安装完成后

    5、安装步骤:分别执行以下命令
    wget http://nginx.org/download/nginx-1.1.10.tar.gz 
    tar -zxvf nginx-1.1.10.tar.gz 
    cd nginx-1.1.10 
    ./configure 
    make 
    make install
    

    期间可能遇到以下错误:
    若报错如下:
    make: * No rule to make target build', needed bydefault’. Stop.

    说明有依赖库没安装 ,继续安装上述几个库。

    6、nginx.tar.gz

    下载nginx.tar.gz安装包进行解压安装,默认是安装在/usr/local/nginx目录下(这样会有全局nginx命令);
    否则在全局下没有nginx命令,需要加软连接,用下面的命令解决,加入你没安装在usr/local下,后者为你的安装目录

    /usr/local/nginx/sbin/nginx -c /root/nginx-1.14.0/conf/nginx.conf
    
    7、查看nginx配置

    到nginx安装目录下,用vim 打开命令打开nginx.conf

    最后一步

    8、启动nginx

    nginx -s reload



    1、不安装SSL报错(nginx:[emerg]unknown directive ssl)

    配置这个SSL证书需要引用到nginx的中SSL这模块,然而我们一开始编译的Nginx的时候并没有把SSL模块一起编译进去,所以导致这个错误的出现。

    2、错误解决步骤

    既然在安装的时候没有编译ssl,难道把nginx卸载重新安装一次?不不不,我们只需要在原有的基础上添加ssl模块就行了。

    • 步骤一:进入之前make好的nginx目录下。

    • 步骤二:来到解压目录下后,按顺序执行一下命令:

    命令1、./configure --with-http_ssl_module  //重新添加这个ssl模块
    
      注意如果没有出现错误,则直接看命令2即可
    `执行以上一条命令出现这个错误(./configure:错误:SSL模块需要OpenSSL库。),原因是因为缺少了OpenSSL,那我们再来安装一个即可执行:yum -y install openssl openssl-devel等待OpenSSL的安装完成后,再执行./configure ,最后在执行” 命令1" 即可。`
    
    命令2、执行make命令,但是不要执行make install,因为make是用来编译的,而make install是安装,不然你整个nginx会重新覆盖的。
    
    命令3、在我们执行完做命令后,我们可以查看到在nginx解压目录下,objs文件夹中多了一个nginx的文件,这个就是新版本的程序了。首先我们把之前的nginx先备份一下,然后把新的程序复制过去覆盖之前的即可。
    
    cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
    cp objs/nginx /usr/local/nginx/sbin/nginx
    
    命令4,最后我们来到Nginx安装目录下,来查看是否有安装ssl模块成功。执行./sbin/nginx -V即可看到如下:
    `nginx version: nginx/1.14.2
    built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) 
    built with OpenSSL 1.0.2k-fips  26 Jan 2017
    TLS SNI support enabled
    configure arguments: --with-http_ssl_module`
    

    相关文章

      网友评论

        本文标题:Linux(centos 7.2)下nginx安装步骤(SSL搭

        本文链接:https://www.haomeiwen.com/subject/vfdicctx.html