centos7.4之Nginx安裝


環境介紹

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 

安裝基礎包

yum -y install gcc gcc-c++ lrzsz wget vim

nginx官網介紹配置安裝:http://nginx.org/en/docs/configure.html

一、安裝nginx依賴的軟件

  nginx是C寫的,需要用GCC編譯;nginx中的rewrite module需要PCRE;nginx中的gzip module需要zlib;nginx中的HTTP SSL module需要OpenSSL。

  已安裝的GCC版本信息如下:

[root@localhost ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) 

  1、zlib源碼安裝:

  zlib下載官網:http://www.zlib.net/

  下載zlib最新版本1.2.11源碼:

[root@localhost plu]# wget http://prdownloads.sourceforge.net/libpng/zlib-1.2.11.tar.gz

  解壓並進入zlib代碼根目錄:

tar zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11

  配置、編譯、安裝:

[root@localhost zlib-1.2.11]# ./configure
[root@localhost zlib-1.2.11]# make
[root@localhost zlib-1.2.11]# make install

  2、pcre源碼安裝:

  PCRE官網:http://www.pcre.org/

  下載PCRE最新版本8.42源碼:

wget  https://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.tar.gz

  解壓並進入PCRE代碼根目錄:

[root@localhost ~]# tar zxvf pcre-8.42.tar.gz 
[root@localhost ~]# cd pcre-8.42

  配置、編譯、安裝:

[root@localhost pcre-8.42]# ./configure
[root@localhost pcre-8.42]# make
[root@localhost pcre-8.42]# make  install

  查看版本

[root@localhost pcre-8.42]# pcre-config --version 
8.42

  3、OpenSSL源碼安裝:

  OpenSSL官網:https://www.openssl.org/

  下載OpenSSL版本1.0.2o源碼:

wget https://www.openssl.org/source/openssl-1.0.2o.tar.gz

  解壓並進入openssl代碼根目錄:

[root@localhost ~]# tar zxvf openssl-1.0.2o.tar.gz
[root@localhost ~]# cd openssl-1.0.2o

  配置、編譯、安裝:

[root@localhost openssl-1.0.2o]# ./config
[root@localhost openssl-1.0.2o]# make
[root@localhost openssl-1.0.2o]# make install

  

二、源碼安裝nginx

nginx最新穩定版本1.14.0

wget http://nginx.org/download/nginx-1.14.0.tar.gz

解壓並進入nginx代碼根目錄:

[root@localhost ~]# tar zxvf nginx-1.14.0.tar.gz
[root@localhost ~]# cd nginx-1.14.0

配置:

[root@localhost nginx-1.14.0]# ./configure --with-http_ssl_module --with-pcre=../pcre-8.42 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.0.2o

編譯安裝:

[root@localhost nginx-1.14.0]# make
[root@localhost nginx-1.14.0]# make install

檢查nginx.conf配置正確性:

[root@localhost nginx-1.14.0]# /usr/local/nginx/sbin/nginx -t  
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

啟動服務

[root@localhost nginx-1.14.0]# /usr/local/nginx/sbin/nginx

 

停止服務

/usr/local/nginx/sbin/nginx -s stop  

命令相關詳見官網:http://nginx.org/en/docs/beginners_guide.html

設置開機自啟動

[root@localhost ~]# chmod 755 /etc/rc.d/rc.local 
[root@localhost ~]# vim /etc/rc.d/rc.local

 

  

 

 

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM