CentOS安装Nginx

时间:2019-09-17
本文章向大家介绍CentOS安装Nginx,主要包括CentOS安装Nginx使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
  1. 在Centos下,yum源不提供nginx的安装,可以通过切换yum源的方法获取安装。也可以通过直接下载安装包的方法,**以下命令均需root权限执行**:
  2.  
    首先安装必要的库(nginx 中gzip模块需要 zlib 库,rewrite模块需要 pcre 库,ssl 功能需要openssl库)。选定**/usr/local**为安装目录,以下具体版本号根据实际改变。

1.安装gcc gcc-c++(如新环境,未安装请先安装)

  1.  yum install -y gcc gcc-c++
     
  2.   yum -y install wget

         3.   yum install -y tar

 2.  安装PCRE库

  1.  cd /usr/local/
  2.  wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz
  3.  tar -zxvf pcre-8.33.tar.gz
  4.  cd pcre-8.33
  5.  ./configure
  6.  make && make install
  7. 如报错:configure: error: You need a C++ compiler for C++ support
  8. 解决:yum install -y gcc gcc-c++

3.安装SSL库

  1. $ cd /usr/local/
  2. $ wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz
  3. $ tar -zxvf openssl-1.0.1j.tar.gz
  4. $ cd openssl-1.0.1j
  5. $ ./config
  6. $ make && make install
 4.安装zlib库存

4.安装nginx

  1.  
    $ cd /usr/local/
  2.  
    $ wget http://nginx.org/download/nginx-1.8.0.tar.gz
  3.  
    $ tar -zxvf nginx-1.8.0.tar.gz
  4.  
    $ cd nginx-1.8.0
  5.  
    $ ./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module

    时提示以下错误:

    ./configure: error: SSL modules require the OpenSSL library.

    支持此命令:

    yum -y install openssl openssl-devel

  6.  
    (注: --with-http_ssl_module:这个不加后面在nginx.conf配置ssl:on后,启动会报nginx: [emerg] unknown directive "ssl" in /opt/nginx/conf/nginx.conf 异常)
  7.  
    $ make && make install
  8.  
    1.  
      报错:./configure: error: the HTTP gzip module requires the zlib library
    2.  
       

    在–prefix后面接以下命令:

    1.  
      --with-pcre=/usr/local/pcre-8.36 指的是pcre-8.36 的源码路径。--with-zlib=/usr/local/zlib-1.2.8 指的是zlib-1.2.8 的源码路径。
    2.  

    查看Nginx 是否正常  

      curl http://localhost

     

原文地址:https://www.cnblogs.com/yingger/p/11532324.html