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

 

  

 

 

  

 

posted @ 2018-05-17 11:34  Charles.L  阅读(3490)  评论(0编辑  收藏  举报