centos7.4之Nginx安装

centos7.4之Nginx安装

环境介绍

1

2

[root@localhost ~]# cat /etc/redhat-release

CentOS Linux release 7.4.1708 (Core)

安装基础包

1

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版本信息如下:

1

2

3

4

5

6

7

8

[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源码:

1

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

  解压并进入zlib代码根目录:

1

2

tar zxvf zlib-1.2.11.tar.gz

cd zlib-1.2.11

  配置、编译、安装:

1

2

3

[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源码:

1

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

  解压并进入PCRE代码根目录:

1

2

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

[root@localhost ~]# cd pcre-8.42

  配置、编译、安装:

1

2

3

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

[root@localhost pcre-8.42]# make

[root@localhost pcre-8.42]# make  install

  查看版本

1

2

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

8.42

  3、OpenSSL源码安装:

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

  下载OpenSSL版本1.0.2o源码:

1

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

  解压并进入openssl代码根目录:

1

2

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

[root@localhost ~]# cd openssl-1.0.2o

  配置、编译、安装:

1

2

3

[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

1

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

解压并进入nginx代码根目录:

1

2

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

[root@localhost ~]# cd nginx-1.14.0

配置:

1

[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

编译安装:

1

2

[root@localhost nginx-1.14.0]# make

[root@localhost nginx-1.14.0]# make install

检查nginx.conf配置正确性:

1

2

3

[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

启动服务

1

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

 

停止服务

1

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

命令相关详见官网:http://nginx.org/en/docs/beginners_guide.html

设置开机自启动

1

2

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

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值