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

     
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章